目录
DML英文全称是Data Manipulation Language(数据操作语言),用来对数据库中表的数据记录进行增、删、改操作。
?
(1)给指定字段添加数据
INSERT INTO 表名 (字段名1, 字段名2, ...) VALUES (值1, 值2, ...);
insert into employee(id,workno,name,gender,age,idcard,entrydate) values(1,'1','Itcast','男',10,'123456789012345678','2000-01-01');
insert into employee(id,workno,name,gender,age,idcard,entrydate) values(1,'1','Itcast','男',-1,'123456789012345678','2000-01-01');
INSERT INTO 表名 VALUES (值1, 值2, ...);
insert into employee values(2,'2','张无忌','男',18,'123456789012345670','2005-01-01');
(3)批量添加数据
INSERT INTO 表名 (字段名1, 字段名2, ...) VALUES (值1, 值2, ...), (值1, 值2, ...), (值1, 值2, ...) ;
INSERT INTO 表名 VALUES (值1, 值2, ...), (值1, 值2, ...), (值1, 值2, ...) ;
insert into employee values(3,'3','韦一笑','男',38,'123456789012345670','2005-01-01'),(4,'4','赵敏','女',18,'123456789012345670','2005-01-01');
注意事项:
UPDATE 表名 SET 字段名1 = 值1 , 字段名2 = 值2 , .... [ WHERE 条件 ] ;
update employee set name = 'itheima' where id = 1;
案例:?修改id为1的数据, 将name修改为小昭, gender修改为 女
update employee set name = '小昭' , gender = '女' where id = 1;
案例:?将所有的员工入职日期修改为 2008-01-01
update employee set entrydate = '2008-01-01';
DELETE FROM 表名 [ WHERE 条件 ] ;
delete from employee where gender = '女';
案例: 删除所有员工
delete from employee;
注意事项: