1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

MYSQL: How to make a combination of 2 columns unique

MYSQL: How to make a combination of 2 columns unique

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

mysqlSetting up some rules in your MySQL database can save you some programming time. This tip will show you how to make a combination of two columns as unique. Suppose you have a database that records BookTitles and Authors. Just having the Author field unique would not make much sense as every Author can have more than one book. But you also don’t want to have an Author / BookTitle combination entered twice. So here we can make the combination of Author and BookTitle unique.

Execute this MySQL statement to make 2 colums unique:

ALTER TABLE TableName ADD UNIQUE (Column1,Column2);

Replace “TableName” with the name of your database table. “Column1″ and “Column2″ are your column names.

Hope this helps.

Happy Programming!

MYSQL: How to make a combination of 2 columns unique

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled

Get Adobe Flash playerPlugin by wpburn.com wordpress themes