电脑

当前位置 /首页/游戏数码/电脑/列表

常用的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

TAG标签:SQL 命令 #