Setting 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!


Social Links