Unique Key in MySql
Posted
by Vinodtiru
on Stack Overflow
See other posts from Stack Overflow
or by Vinodtiru
Published on 2010-03-12T04:15:09Z
Indexed on
2010/03/12
4:17 UTC
Read the original article
Hit count: 429
I have a table with four Columns. Col1, Col2, Col3, and Col4. Col1, Col2, Col3 is string and Col4 is a integer primary key with Auto Increment. Now my requirement is to have unique combination of Col2 and Col3.
I mean to say like.
Insert into table(Col1,Col2,Col3) Values('val1','val2','val3'); Insert into table(Col1,Col2,Col3) Values('val4','val2','val3');
the second statement has to throw error as the same combination of 'val2','val3' is present in the table. But i cant make it as a primary key as i need a auto increment column and for that matter the col4 has to be primary. Please let me know a approach by which i can have both in my table.
Any kind of help is appreciated. Thanks.
© Stack Overflow or respective owner