MySQL - Correct Way To Use The UNIQUE KEY - Stack Overflow
MySQL - Correct Way To Use The UNIQUE KEY - Stack Overflow
- Stack Overflow
Welcome to Q&A for professional and enthusiast programmers check out the FAQ!
log in | careers | dev days | chat | meta | about | faq
search
Questions
Tags
Users
Badges
Unanswered
Ask Question
60230
MySQL table. CREATE TABLE ab ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, pid INT UNSIGNED NOT NULL DEFAULT 0, aid INT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY (pid, aid) );
mysql
That depends on what you need it to do, which you haven't provided any detail about. OMG Ponies Oct 30 '10 at 19:13 @OMG Ponies what do you mean? slang Oct 30 '10 at 19:14 Elaborate please? Unique key would ensure that the values inserted are always unique (no duplicates are allowed). Pavanred Oct 30 '10 at 19:16 So my UNIQUE Key is wrong for my data? slang Oct 30 '10 at 19:17 Presentation Layer (HTML5/JQUERY) Architect for Innovative CREATETHE GROUP New York, NY; United States Sr. Software Engineer (Ruby on Rails) Sharethrough San Francisco, CA view more jobs
feedback
1 Answer
active
oldest
votes
Related
The unique index you have created is a valid index. It creates an index which allows duplicate values in pid and also in aid but does not allow duplicates of any pair (pid, aid) . For example, this insert would fail if your table already contains the data from your example because it conflicts with the second row: INSERT INTO ab (pid, aid) VALUES (3, 2)
link | improve this answer answered Oct 30 '10 at 19:17 Mark Byers
MySQL ON DUPLICATE KEY UPDATE with nullable column in unique key Can't create mysql table with foreign key Mysql foreign key by non unique key how is that possible? mysql unique key and index
Best way to have unique key over 500M varchar(255) records in mysql/innodb? MySQL 'UPDATE ON DUPLICATE KEY' without a unique column? MySQL - Cannot insert NULL value in column, but I have a default value specified? MySQL query problem MySQL query design question MySQL table structure question MySQL table structure question MySQL syntax Error; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4 MYSQL - how to a second unique string key?
feedback
Your Answer
MySQL UPDATE conflicts with unique key MySQL unique behavior on NULL columns mysql error 1451 mysql unique key MySQL Enum correct use? what datatype to use for MySQL unique key/index What is the correct way to print out multiple data using MYSQL? Is There a Unique Record Key for Mysql? mySQL Using on Duplicate Key on index that is not unique why Mysql is giving me error 1280 "Wrong Index"
Name Email
or
Duplicate unique key error after rollback in mysql how to drop unique key on foreign key in mysql?
log in
Home Page
Not the answer you're looking for? Browse other questions tagged mysql or ask your own question.
question feed
about | faq | blog | chat | data | podcast | shop | legal | advertising info | mobile | contact us | feedback
stackoverflow.com api/apps careers serverfault.com superuser.com meta area 51 webapps gaming ubuntu webmasters cooking game development math photography stats tex english theoretical cs programmers unix apple wordpress physics home improvement gis electronics android security bicycles dba
site design / logo 2011 stack exchange inc; user contributions licensed under cc-wiki with attribution required
rev 2011.8.27.1