查询

查询所有列

select * from 表名;
例:
select * from classes;

查询指定列

可以使用as为列或表指定别名

select 列1,列2,... from 表名;
例:
select id,name from classes;

增加

说明:主键列是自动增长,但是在全列插入时需要占位,通常使用0,插入成功后以实际数据为准

全列插入:值的顺序与表中字段的顺序对应

insert into 表名 values(...)
例:
insert into students values(0,’郭靖‘,1,'蒙古','2016-1-2');

部分列插入:值的顺序与给出的列顺序对应

insert into 表名(列1,...) values(值1,...)
例:
insert into students(name,hometown,birthday) values('黄蓉','桃花岛','2016-3-2');

上面的语句一次可以向表中插入一行数据,还可以一次性插入多行数据,这样可以减少与数据库的通信

全列多行插入:值的顺序与给出的列顺序对应

insert into 表名 values(...),(...)...;
例:
insert into classes values(0,'python1'),(0,'python2');
insert into 表名(列1,...) values(值1,...),(值1,...)...;
例:
insert into students(name) values('杨康'),('杨过'),('小龙女');

修改

update 表名 set 列1=值1,列2=值2... where 条件
例:
update students gender=0,hometown='古墓' where id=5;

删除

delete from 表名 where 条件
例:
delete from students where id=5;

逻辑删除,本质就是修改操作

update students set isdelete=1 where id=1;