mysql常用DML命令

DML是对数据库表中的数据增删改的操作.


 1.插入数据:

insert into emp(id,name,sex,birthday,salary) values (1,'dupudupu','','2011-09-08',1000);

也可以这样写,省略前面括号里面的内容

insert into emp values (2,'Paul','','2018-09-22',800);

 批量插入:

insert into emp values 
(3,'Lili','','2017-06-25',3000),
(4,'Hali','','2014-09-08',1000),
(5,'Soso','','1997-07-30',10000),
(6,'Mama','','1789-03-25',8888);

3.修改数据:当我在Mysql Workbench中使用下面的语句时,出现了错误

update emp set name='Dupu' where id = 1;

首先语句是没有错的,经查询

  • 错误原因:是在safe mode下,要强制安全点,update只能跟where
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
  • 解决方案 : 执行命令---->SET SQL_SAFE_UPDATES = 0;

4.删除数据

delete from emp where id=6;

posted on 2018-08-06 20:42  董大志  阅读(1263)  评论(0)    收藏  举报

导航