DML数据操作(增删改)
INSERT插入
给指定字段插入数据
insert into 表名 (字段1,字段2...) values (值1,值2);
- 向itcast的worker表的制定字段中插入一条新数据
insert into workers
(id, workNo, name, gender, age, idCard, entryDate) values
(1,'1','hikari39','女',20,'100000000000000000','2004-05-24');
- 查看插入的新数据
select * from workers;
- 向itcast的workers表的制定字段(部分)中插入新数据
insert into workers
(id,workNo)
values
(3,'3');
- 没有填写的字段为null
给所有字段插入数据
insert into 表名 values (值1,值2,...);
- 向itcast中的workers表的全部字段插入数据
#向所有字段插入数据
insert into workers values
(2,'2','cat','男','100','100000000000000000','2024-03-07');
#展示数据
select * from workers;
批量添加数据(指定字段)
insert into 表名 (字段1,字段2...) values (值1,值2,...),(值1,值2,...);
批量添加数据(所有字段)
insert into 表名 values (值1,值2,...),(值1,值2,...);
- 实例
insert into workers values
(4,'4','hiten','男',90,'100000000000000000','2004-05-24'),
(5,'4','hiten','男',90,'100000000000000000','2004-05-24'),
(6,'4','hiten','男',90,'100000000000000000','2004-05-24');
UPDATE修改
修改数据
update 表名 set 字段1=值1, 字段2=值2,... [where 条件];
- 实例
#将workNo字段值为'4'的记录的
#name字段替换为'jill'
#gender字段替换为'gender'
update workers set name='jill',gender='女' where workNo = '4';
- 实例2
#将所有员工的入职日期替换为2000-01-01
update workers set entryDate='2000-01-01';
DELETE删除
delete from 表名 [where 条件];
- 实例
#删除gender为'女'的员工
delete from workers where gender = '女';
标签:...,insert,into,DML,字段,values,MYSQL,增删,workers
From: https://www.cnblogs.com/HIK4RU44/p/18060762