Home > Database > Mysql Tutorial > body text

php mysql update遇到unique索引则删除本纪录

WBOY
Release: 2016-06-06 09:39:18
Original
1267 people have browsed it

mysqlphp索引

图片说明

uid和book_id有联合unqiue索引,即一个人只能有一本书

需求: 更新11和14行,使uid=1005,若产生unique索引冲突(13和14行),则删除待更新的行(14行)

我能想到的办法是,先select待更新行并保存,同时删除(delete)这些行,再用insert IGNORE 插入。

这样太笨了,有没有操作mysql的方法,比如触发器什么的,或者更高效的,求教!!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template