一推网

当前位置: 首页 > 知识问答 > mysql插入语句的方法

知识问答

mysql插入语句的方法

2026-11-22 18:12:30 来源:互联网转载

mysql插入语句的方法:

mysql中常用的三种插入数据的语句:

insert into表示插入数据,数据库会检查主键(PrimaryKey),如果出现重复会报错;

replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引的话,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样;

insert ignore表示,如果中已经存在相同的记录,则忽略当前新数据;

下面通过代码说明之间的区别,如下:create table testtb(id int not null primary key,name varchar(50),age int);insert into testtb(id,name,age)values(1,"bb",13);select * from testtb;insert ignore into testtb(id,name,age)values(1,"aa",13);select * from testtb;//仍是1,“bb”,13,因为id是主键,出现主键重复但使用了ignore,则错误被忽略replace into testtb(id,name,age)values(1,"aa",12);select * from testtb; //数据变为1,"aa",12

推荐教程: 《mysql教程》

mysql插入语句

上一篇:谁能推荐一个开源的微信公众号后台管理系统?

下一篇:excel表格怎么画斜线一分为三_excel表格画斜线一分为三教程