一、插入
1.value
1.NOT NULL 的字段必须写
2.可以互换位置,但是保持字段与值位置对应
3.可以省略列名,默认所有列,所有值都得写,且值必须与表中顺序一致
4.支持多行
5.支持子查询
INSERT INTO BEAUTY(ID, NAME, SEX, BORNDATE, PHONE, PHOTO, BOYFRIEND_ID)
VALUES(13,2,'女', '1990-4-03', 18777777777, NULL, 2),
(14,2,'女', '1990-4-04', 18777777777, NULL, 3);
INSERT INTO BEAUTY
VALUES(13,2,'女', '1990-4-03', 18777777777, NULL, 2);
INSERT INTO BEAUTY
SELECT (15,2,'女', '1990-4-04', 18777777777, NULL, 3);
2.set
INSERT INTO BEAUTY
SET ID=19, NAME='3', PHONE='999';
二、修改
1.单表修改
UPDATE BEAUTY B SET B.`PHONE` = '18888888888', B.`BOYFRIEND_ID` = 3
WHERE NAME LIKE '%三%';
2.多表修改
UPDATE BOYS B1
INNER JOIN BEAUTY B2 ON B1.`ID` = B2.`BOYFRIEND_ID`
SET B2.`PHONE` = '18888888888'
WHERE B1.`BOYNAME` = '张无忌'
三、删除
1.delete
1.能添加where 条件
2.有返回值
3.可以回滚
DELETE FROM BEAUTY B WHERE B.PHONE LIKE '%999'
DELETE B, B1 -- 写几个别名就删几个表的记录
FROM BEAUTY B
INNER JOIN BOYS B1 ON B.`BOYFRIEND_ID` = B1.`ID`
WHERE B1.`BOYNAME` = '张无忌';
2.truncate
1.truncate不能添加where 条件
2.效率高一点
3.删除后,自增长列的值重新从1开始
4.没有返回值
5.不能回滚
TRUNCATE TABLE BOYS; -- 清空表