MYSQL: make a combination of 2 columns unique
by Gabi SolomonHere is a recently situation i came across, what if you have a table and you want to make a combination of 2 columns unique. The columns Individually are not unique, but combination is.
To alter 1 column to a unique key you would use :
SQL:
-
ALTER TABLE user MODIFY COLUMN id INT NOT NULL UNIQUE;
Well for a combination of 2 or more columns to be unique you would use:
SQL:
-
ALTER TABLE user ADD UNIQUE (id,domain);
Hope this helps you.
Cheers
Related Posts
-
Rajesh Katragadda
-
http://www.cuhk.edu.hk/chorus Quofei
-
http://garlix.com/ Daniel
-
ramigb

