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

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

WBOY
WBOYOriginal
2016-06-13 12:34:16972browse

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

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

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



哪种方式效率高点呢?

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