當前位置:妙知谷 >

遊戲數碼 >電腦 >

常用的SQL命令

常用的SQL命令

常用的sql命令在程序員編程時會為我們帶來方便,下面總結一下,希望能幫助你。

常用的SQL命令

操作方法

(01)查詢數據記錄(Select)語法:Select 字段串行 From table Where 字段=內容例子:想從book表中找出作者為"cancer"的所有記錄,SQL語句便如下:select * from book where author=’cancer’"*"是取出book表所有的字段,如查詢的字段值為數字,則其後的"內容"便無須加上單引號,如是日期,則在Access中用(#)包括,而在SQL server中則用(’)包括,如:select * from book where id=1select * from book where pub_date=#2002-1-7# (Access)select * from book where pub_date=’2002-1-7’ (SQL Server)提示:日期函數to_date不是標準sql文,不是所有的數據庫適用,所以大家在使用的時候要參考數據庫具體語法另外如果是查詢傳入的變量,則如下:strau=("author")strsql="select * from book where author=’"&strau&"’"如果查詢的是數字,則:intID=("id")strsql="select * from book where id="&intID在很多數據庫中,如:oracle,上面的語句是可以寫成:strsql="select * from book where id='"&intID&"'"的。但是字符型一定不能按照數字格式寫,需要注意。

常用的SQL命令 第2張

(02)添加記錄(Insert)語法:Insert into table(field1,field2,....) Values (value1,value2,....)例子:添加一作者是"cancer"的記錄入book表:insert into book (bookno,author,bookname) values (’CF001’,’cancer’,’Cancer無組件上載程序’)同樣,如果用到變量就如下:strno=("bookno")strau=("author")strname=("bookname")strsql="insert into book (bookno,author,bookname) values (’"&strno&"’,’"&strau&"’,’"&strname&"’)"

(03)用Recordset對象的Addnew插入數據的方法:語法:ewrs("field1")e=value1rs("field2")e=te

常用的SQL命令 第3張

(04)修改數據記錄(Update)語法:update table set field1=value1,field2=value2,e fieldx=valuex例子:update book set author=’babycrazy’ where bookno=’CF001’如果用到變量就如下:strno=("bookno")strau=("author")strsql="update book set author=’"&strau&"’ where bookno=’"&strno"’"

(05)刪除一條記錄(Delete)語法:Delete table where field=value例子:刪除book表中作者是cancer的記錄delete book where author=’cancer

標籤: SQL 命令
  • 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/sm/diannao/6mxgk3.html