CREATE DATABASE databasename
drop database dbname
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
DROP TABLE tablename
Alter table tabname add column col type
列增加后将不能删除
Alter table tabname add primary key(col)
Alter table tabname drop primary key(col)
create [unique] index idxname on tabname(col….)
drop index idxname
索引是不可更改的,想更改必须删除重新建
create view viewname as select statement
drop view viewname
select * from table1 where 范围
insert into table1(field1,field2) values(value1,value2)
delete from table1 where 范围
update table1 set field1=value1 where 范围
select * from table1 where field1 like ’%value1%’
select * from table1 order by field1,field2 [desc]
select count as totalcount from table1
select sum(field1) as sumvalue from table1
select avg(field1) as avgvalue from table1
select max(field1) as maxvalue from table1
select min(field1) as minvalue from table1
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
左连接结果集包括连接表的匹配行,也包括左连接表的所有行
select a,b,c from a where a IN (select d from b )
select * from table1 where time between time1 and time2
between限制查询数据范围时包括了边界值
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
参考:经典SQL语句大全(绝对的经典)