Skip to content

DML语句

1. insert语句

sql
-- 常规批量插入
insert into x values (5, 90), (8, 80);
-- binlog文件中记录就是这样
insert into x values a=5, b=90;
-- 查询插入
insert into x select * from y;

2. update语句

sql
update sql_trains.x set a=a+1 and b=a+10 where a=2;

3. delete语句

sql
delete from x where a not in(select a from y);
-- 关联删除
delete x,y from x left join y on x.a= y.a where y.a is NULL;

4. 联合使用

sql
-- 如果有重复继续执行update操作
insert into x values (2) on duplicate key update a=a + 10:
-- 如果没有就插入,有就先删除再插入
replace into sql_trains.x values (2, 30);