CRUD操作:
create 创建
read 读取
update 修改
delete 删除
1、添加数据
insert into Info values(‘p009‘,‘张三‘,1,‘n001‘,‘2016-8-30‘);
给特定的列添加数据
insert into Info (code,name) values(‘p009‘,‘张三‘);
自增长列的处理
insert into family values(‘‘,‘p001‘,‘数据‘,‘t001‘,‘数据‘,1);
2、删除数据
删除所有数据
delete from family
删除特定数据
delete from info where code=‘p001‘
3、修改数据
修改所有
update info set name=‘‘
修改特定数据
update info set name=‘‘ where code=‘p002‘
修改多列
update info set name=‘‘,sex=1 where code=‘p002‘
4、读取数据
(1)简单读取,查询所有列(*)所有行(没有加条件)
select * from info
(2)读取特定列
select code,name from info
(3)条件查询
select * from info where code=‘p003‘
(4)多条件查询
select * from info where code=‘p003‘ or nation=‘n002‘ #或
select * from info where sex=0 and nation=‘n002‘ #与
(5)关键字查询(模糊查询)
查所有包含奥迪的汽车
select * from car where name like ‘%奥迪%‘; # %百分号代表任意多个字符
查以‘皇冠‘开头的所有汽车
select * from car where name like ‘奥迪%‘;
查询汽车名称中第二个字符是‘马‘的
select * from car where name like ‘_马‘; # _下划线代表任意一个字符
(6)排序查询
select * from car order by powers #默认升序排列
select * from car order by powers desc #升序 asc 降序desc
先按brand 升序排 再按price降序排
select * from car order by brand,price desc