1. 插入语句
INSERT INTO beauty (
id,
NAME,
sex,
borndate,
phone,
photo,
boyfriend_id
)
VALUES
(
13,
‘唐艺昕‘,
‘女‘,
‘1990-4-23‘,
‘18934531234‘,
NULL,
2
);
方式1:字段的值写null
方式2:不写该字段
INSERT INTO beauty(NAME, sex, id, phone)
VALUES(‘蒋欣‘, ‘女‘, 16, ‘110‘);
INSERT INTO beauty
VALUES(18, ‘李易峰‘, ‘男‘, NULL, ‘19‘, NULL, NULL);
INSERT INTO beauty SET id = 19,
NAME = ‘刘涛‘,
phone = ‘999‘ ;
INSERT INTO beauty
VALUES
(20, ‘李易峰‘, ‘男‘, NULL, ‘19‘, NULL, NULL),
(21, ‘李易峰‘, ‘男‘, NULL, ‘19‘, NULL, NULL),
(22, ‘李易峰‘, ‘男‘, NULL, ‘19‘, NULL, NULL);
INSERT INTO beauty(id, NAME, phone)
SELECT 26, ‘送钱‘, ‘12341234‘;
2.修改语句
update 表名
set 列=新值,列=新值…
where 筛选条件;
sql99语法:
update 表1 别名
inner | left | right join 表2 别名
on 连接条件
set 列=值,…
where 筛选条件;
修改单表的记录
UPDATE
beauty
SET
phone = ‘109090909‘
WHERE NAME LIKE ‘唐%‘ ;
UPDATE
boys
SET
boyname = ‘张飞‘,
usercp = 10
WHERE id = 2 ;
修改多表的记录
UPDATE
boys b
INNER JOIN beauty be
ON b.`id` = be.`boyfriend_id` SET be.`phone` = ‘114‘
WHERE b.`boyName` = ‘张无忌‘ ;
UPDATE
boys b
RIGHT JOIN beauty be
ON b.`id` = be.`boyfriend_id` SET be.`boyfriend_id` = 2
WHERE be.`boyfriend_id` IS NULL ;
3.删除语句
delete from 表名 where 筛选条件
sql99语法
delete 别名(要删哪个表就写哪个表的别名,都删就都写)
from 表1 别名
inner | left | right join 表2 别名 on 连接条件
where 筛选条件
limit 条目数;
DELETE
FROM
beauty
WHERE phone LIKE ‘%9‘ ;
DELETE
be
FROM
beauty be
INNER JOIN boys b
ON b.`id` = be.`boyfriend_id`
WHERE b.`boyName` = ‘张无忌‘ ;
DELETE
b,
be
FROM
beauty be
INNER JOIN boys b
ON b.`id` = be.`boyfriend_id`
WHERE b.`boyName` = ‘黄晓明‘ ;
truncate table 表名;
TRUNCATE TABLE boyes ;
原文链接:https://blog.csdn.net/qq_21579045/article/details/98111827
原文:https://www.cnblogs.com/hxl-learning-space/p/14594340.html