Home  >  Article  >  Database  >  【MySQL】replace into 用法总结

【MySQL】replace into 用法总结

WBOY
WBOYOriginal
2016-06-07 15:17:46954browse

REPLACE的运行与INSERT很相。只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有相同的,则在新记录被插入之前,旧记录被删除。 注意,除非表有一个PRIMARY KEY或UNIQUE索引,否则,使用一个REPLACE语句没有意义。该语句

REPLACE的运行与INSERT很相似。只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有相同的值,则在新记录被插入之前,旧记录被删除。 

注意,除非表有一个PRIMARY KEY或UNIQUE索引,否则,使用一个REPLACE语句没有意义。该语句会与INSERT相同,因为没有索引被用于确定是否新行复制了其它的行。


下面是replace into的一个坑:

 http://blog.xupeng.me/2013/10/11/mysql-replace-into-trap/



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn