UNIQUE
In SQL, UNIQUE constraint uniquely identifies each record in a database table.
There can be many UNIQUE constraints per table. A Unique key column contain NULL values in table.
PRIMARY KEY can also be used instead of UNIQUE constraint. But the UNIQUE constraint can be used more than once in a table. But PRIMARY KEY can be used only once in a table.
Syntax :-
column_name data_type UNIQUE KEY
Example : The following SQL statement creates a table named students and specifies the roll no column as unique. That means this field does not allow duplicate values.
Query :
Output :
CREATE TABLE students
(
stu_id int(5),
name varchar(50),
roll int(5) UNIQUE KEY,
city varchar(50)
);
Now, You can see in students table roll is UNIQUE key.
0 Comments