谈谈数据库sql语句

来源:互联网 发布:vb傻瓜书 编辑:程序博客网 时间:2024/06/14 21:40

1、SQL(structured Query Language)


2、创建表:create table 表名(column1 datatype (length) ,column2 datatype (length),...)


3、插入语句:insert into table(field1,field2) values(value1,value2)


4、更新语句:update table set field1=value1,field2=value2 where field3=value3(set后多个条件用逗号 而不是and,where后多个条件用and)


5、删除语句:delete from table where field=value


6、查询语句:select * from table查询表内所有内容(无条件查询)

select field1 from table where field2=value1(有条件查询)

select field1,field2 from table(多个字段查询)

select field1 as field3,field2 as field4 from table(给字段设置别名,as可以省略)

select DISTINCT field1 as field2 from table(distinct 选择不重复的结果) 

select field1 from table where field2<>10(筛选字段小于10的结果)(<>不等于,!=不等于)(any, some 任何一个)(all所有的)


7、模糊查询:select * from table where f like 'g%'(g开头的所有结果都可以查出)(like不和%和_一起使用,就相当于=)

select * from table where f like '%g'(g结尾的所有结果都可以查出)

select * from table where field like 'g_'(_代表一个字符)

select * from table where field like '\%%'(\%代表将%转义)

select * from table where field like 'a%%' ESCAPE 'a'(a相当于\)


8、 逻辑符合条件关键字:not 、or 、and

select * from table where filed1=value1 or field1=value2与select * from table where field1 in(2,3)相同9、对查询结果进行排序

select * from table where field in(2,3) ORDER BY field desc(降序)

select * from table where field in(2,3) ORDER BY field asc(升序)







                     


原创粉丝点击