dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Jan 14, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Understanding the Unique Keyword in MySQL

At times, we need a certain combination of column values to be unique in a table. With MySQL, this can be achieved using the UNIQUE keyword.

There can be a combination of one or more keys and the same will be validated before inserting the data to the table.

Example: Table named DETAILS is created as below.

CREATE TABLE 'Details' (
   'ai' INT(11) NOT NULL ,
   'name' VARCHAR(50) NULL DEFAULT NULL ,
   'address' VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8_bin',
   UNIQUE (ai,name)
)
COLLATE='utf8_bin'
ENGINE=InnoDB; 

This ensure that the values in column ai and name combined are unique in nature. This can be made for any combination of columns.

M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date