- 插入单行
insert into <表名> values (列值) - 将现有数据添加到某个已有的表中
insert into <被添加表名>(列,列,列) select 列,列,列 from <现有表名> - 将现有数据填充一个新表
select 列,列,列 into <新建表名> from <现有表名> - 插入多行
insert <表名>(列,列,列)
select 列,列,列 union
select 列,列,列
删除行
delete from <表名> where 条件删除表
drop table tablename 删除内容及定义 ,释放空间
truncate table tablename 删除内容,但不删除定义
delete table where 条件 删除符合条件的内容
- 修改表
update <表名> set 列名=更新值 where 条件
- 查询所有
select * from 表名 - 部分查询
select 列,列,列 from 表名 where 条件 - 精确查询
select 列,列,列 from 表名 where 条件 order by 需排序的列名asc/desc - 查询并更改列名
select 列 as 新列名 from 表名 where 条件 查询空行
select 列 from 表名 where 条件=null查询中使用常量
select 列, 变量名 as 新列名 from 表名 //查询并显示表列,并添加新列,值为“变量名”限制返回数量
select top num 列 from 表名 //显示前num行
select top num percent 列 from 表名 //显示其num%
like进行字符串的模糊查询
select * from 表名 where 列名 like ‘张三’使用between进行范围内的查询
select * from 表名 where 列名 between num1 and num2使用in进行枚举查询
select 列 from 表名 where 列名 in (值,值,值)使用group by进行分组筛选
select 列 as 新列名, 列 as 新列 from 表名 group by 列使用having进行分组筛选
select 列 as 新列名, 列 as 新列 from 表名 group by 列 having 条件
查询多表
select a.name,b.age from a,b where a.name=b.name内联接查询
select a.name,b.age from a inner join b on ( a.name=b.name)外联接查询(左右)
select a.name,b.age from a left outer join b on ( a.name=b.name)
select a.name,b.age from a right outer join b on ( a.name=b.name)