Home > Backend Development > PHP Tutorial > 安插数据用UNIQUE好呢还是插入前用count(*)查询效率高?

安插数据用UNIQUE好呢还是插入前用count(*)查询效率高?

WBOY
Release: 2016-06-13 11:39:15
Original
906 people have browsed it

插入数据用UNIQUE好呢还是插入前用count(*)查询效率高??
一个表不允许插多条  title + url 同时相同的数据。

方式A: 用 UNIQUE 约束,代码只需直接执行语句 insert ignore into ........

方式B: select count(*) from mytable where title=? and url=?
        结果为零才执行 insert into ....



哪种方式效率高点呢?

UNIQUE? 约束 insert
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