查询
select * from table where 字段
删除
delete from table where 字段
delete from 表名 where 字段like '%%'
删除指定行之外的所有行
delete from 表名 where 字段<>(select max(id) from OilInfo)
delete from 表名 where 字段<>值
添加
insert into table values ( 内容,内容,.. )
修改/更新
update table set 字段 where
模糊查询
select * from table where 字段 like %111%
倒序排序
select * from table order by 字段 desc
顺序排序
select * from table order by 字段 asc
总数
select count(*) from table where 字段
求和
select sum(字段) as sumvalue from table
平均值
select avg(字段) as avgvalue from table
最大值
select max(字段) as maxvalue from table
最小值
select min(字段) as minvalue from table
主键:primary key
自动增长列:identity
外键:references
默认:default
视图
创建
create view viewname
删除
drop view viewname
索引
创建
create index idxname
删除
drop index idxname
外连接
左连接:
left (outer) join
右连接:
right (outer) join
连表查询
select * from 表a (inner) join 表b on 表a.Id=表b.Id --两表联查
select * from 表a inner join 表b on 表a.Id=表b.Id inner join 表c inner join 表b on 表b.Id=表c.Id --三表联查
分组
select 字段 from table group by 字段