基本的增、删、改、查
增
insert into tbname values () 字段顺序要对应表的字段顺序
insert into tbname (column1,column2,column3....) values (values1,values2,values3...)
删
delete from tbname
改
update tbname set column1=values1,column1=values2...
查
select * from tbname
修改字段类型
alter table tbname modify 字段 类型(长度) ;
修改字段名
alter table tbname rename 字段旧 to 字段新;
修改原有字段名称及类型:
alter table tbname change 字段旧 字段新 类型 ;
添加字段
alter table 表名 add (字段 类型 not null);
删除字段
alter table 表名 drop column 字段;
添加注释
/*oracle*/ comment on column 表名.列名 is '备注';
/*mysql*/ alter table 表名 modify 字段名 类型 comment '备注';
还有一些常用的联结查询、函数
select * from a left join b on a.id=b.aid 左联结以左表为主,右表没有的值 显示为NULL
select * from a right join b on a.id=b.aid 右联结
select * from a,b where a.id=b.aid 外联结
聚合函数 sum avg min max count 用有group by 的sql语句
len() 长度
cast() 类型转换
union 和 union all union 会自动删除重复的项
row_num () over (partition by 字段 order by ) 开窗函数
分页查询
mysql: select * from 表名 limit start,pagesize
oracle: select * from (select a.*,rownum rn from 表名 where rownum<=end) a where a.rn>=start;
sqlserver:select * from (select 列名,row_num () over(order by 列名1) as rn from 表名) as t
where t.列名1>=start and t.列名1<=end;