Is it better to use UNIQUE to insert data? is it still highly efficient to query data with count (*) before insertion?
Source: Internet
Author: User
Is it better to use UNIQUE to insert data, or is it more efficient to use count (*) to query data before insertion ?? You cannot insert multiple & nbsp; title & nbsp; + & nbsp; URLs & nbsp; in a table with the same data. Method A: & nbsp; use & nbsp; UNIQUE & nbsp; constraints. you only need to directly execute the statement & nbsp; insert & nbsp; is it better to use UNIQUE to insert data, or is it more efficient to use count (*) to query data before insertion ??
A table cannot insert multiple entries of data with the same title + url.
Method A: use the UNIQUE constraint. the code only needs to directly execute the insert ignore ........
Method B: select count (*) from mytable where title =? And url =?
Insert ....
Which method is more efficient?
------ Solution --------------------
How is the first method highly efficient ......
------ Solution --------------------
Agree to the upstairs, but no tests have been conducted
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.