目录
数据操作语言:
一、插入:(insert)
插入语句有两种形式:
方案一
insert into tablename(column1,column2,...) values(value1,value2,...);
insert into tablename set column1=value1,column2=value2...
#1.播入的值的类型要与列的类型—致或兼容
INSERT INTO beauty
(id,NAME,sex,borndate,phone,photo,boyfriend_id)
VALUES (13,'唐艺昕','女', '1990-4-23','1898888888 ',NULL,2);
#1.2.不可以为null的列必须插入值。可以为null的列如何插入值?
#方式一:
INSERT INTO
beauty (id,NAME,sex, borndate, phone,photo, boyfriend_id)
VALUES (13,'唐艺昕','女','1990-4-23','1898888888',NULL,2);
#方式二:
INSERT INTO
beauty(id,NAME,sex,borndate, phone, boyfriend_id)
VALUES (14,'唐艺昕予,'女','1990-4-23','1898888888',2);
方案二:
INSERTINTO beauty
SET id=19,NAME='文刘涛', phone='999';
方案对比:
1、方式一支持插入多行
INSERT INTo beauty
VALUES(23,'唐艺昕1','女','1990-4-23' , '1898888888',NULL,2),
(24,'唐艺听2','女','1990-4-23' , '1898888888',NULL,2),
(25,'唐艺昕3','女','1990-4-23','1898888888',NULE,2);
2、方式一支持子查询,方式二不支持
INSERT INT○
beauty(id,NAME,phone)
SELECT 26,'末茜','11809866';
二、修改:(update)
#1.修改单表的记录
#案例1:修改beauty表中姓唐的女神的电话为13899888899
UPDATE beauty SET phone = '13899888899'
WHERE NAME LIKE '唐%';
#2.修改多表的记录
案例:修改张无忌的女朋友的手机号为114
UPDATE boys bo
INNER JOIN beauty b
ON bo.`id`=b.`boyfriend_id`
SET b.`phone`='114'
WHERE bo.`boyName`='张无忌';
三、删除:delete
删除语句/*
方式一: delete语法:
delete from表名where筛选条件
#案例1:删除手机号以s结尾的女神信息
DELETE FROM beauty WHERE phone LIKE '号9';
#2.多表的删除
#案例:删除张无忌的女朋友的信息
DELETE b, bd
FROM beauty b
INNER JOIN boyg bo
oN b.`boyfriend_id`=bo.`id`
WHERE bo.`boyName`='张无忌';