drop table Student 删除表
alter table RenYuan add CC int 修改表,往人员表里添加一个int类型叫CC的列
alter table RenYuan drop column CC 删除CC这一列
drop datebase CeShi 删除数据库
create 添加数据
read 读取数据*
update 修改数据
delete 删除数据
1 添加数据
insert into Nation values('n002','回族') 可以把括号内的内容加单引号,将其变为字符串类型,insert一次添加一行
insert into Nation values('n003','') 只添加代号不添加民族,列的添加不能为空
insert into Nation(code,name) vlaues('n004','维吾尔族')
2 删除数据
delete from Nation 删除Nation中所有数据
delete from Friends where ids = 5 删除Friends中ids为5的数据
3 修改数据
update Friends set fcode='p016' 修改所有
update Friends set fcode='p006' where ids = 6修改ids为6的行的fcode为p006
update Friends set fcode='p006',mcode='p002' where ids = 6、

 

 

查询
1 简单查询
select * from Info 查询info表中所有数据 *代表所有列
select Code,Name from Info 查询info表中的code和name列
select Code as '代号',Name as '姓名' from Info 给列指定别名
2 条件查询
select * from Info where Code='p001'
select * from Info where Sex='true' and Nation='n001'
3 范围查询
select * from Car where Price>40 and Price<50(between 40 and 50) 括号里的写法达到的功能和前面相同,简便
4 离散查询
select *from Car where Code in ('c001','c005','c010') 通过在in前面加not可以实现反选
5 模糊查询
select * from Car where Name like '%宝马%' 查包含宝马的 %代表任意多个字符,仅限在模糊查询中使用
select * from Car where Name like '宝马%' 查以宝马开头的
select * from Car where Name like '%宝马' 查以宝马结尾的
select * from Car where Name like '__E%' 查询第三个字符是E的 _代表一个字符
6 排序查询
select * from Car order by Price order by根据by后面的关键词进行排序,默认升序
select * from Car order by Price desc desc为降序
select * from Car order by Oil desc,Price asc 前面的是主要的,先根据主要的排,再根据次要的
7 分页查询
select top 5 * from Car
select top 5 * from Car where Code not in (select top 5 Code from Car)
当前页:page=2 每页显示row =10
select top row * from Car where Code not in (select top (page-1)*row Code from Car)
8 去重查询
select distinct Brand from Car 把重复的Brand值去掉
9 分组查询
select * from Car group by Brand having count(*)>2 根据Brand进行分组,条件是数量大于2 count(*)代表个数
10 聚合函数(统计查询)
select count(*) from Car 查询所有数据条数
select count(Code) from Car查询Code的条数
select sum(Price) from Car 求价格和
select avg(Price) from Car 平均
max 最大
min 最小