Saturday, 19 November 2011


The UNIQUE constraint identifies unique for each record in a database table.
i.e. a value entered in column defined in the unique constraint must not be repeated across the column.
A PRIMARY KEY constraint automatically(Set) in UNIQUE constraint defined.
Note: You can have set many UNIQUE constraints per table, but only one set PRIMARY KEY constraint per table.

UNIQUE constraint defined at the Column level

Syntax:
CREATE TABLE Table_Name
(
Column_Name1 Datatype(size) UNIQUE,
Column_Name2 DataType(Size) UNIQUE,
......
);
Example Statement:
SQL> CREATE TABLE Student_Detail
(
S_No number(2) UNIQUE,
Name varchar(25),
Address varchar(70),
City varchar(20)
);

UNIQUE constraint defined at the Table level

Syntax:
CREATE TABLE Table_Name
(
Column_Name1 Datatype(size),
Column_Name2 DataType(Size),
......
UNIQUE (Column_Name1,Column_Name2,..)
);
Example Statement:
SQL> CREATE TABLE Student_Detail
(
S_No number(2),
Name varchar(25),
Address varchar(70),
City varchar(20),
UNIQUE (S_No)
);
Main difference between primary key and unique constraint is: unique constraint allows NULL values.

0 comments:

Post a Comment

TrainingHUB. Powered by Blogger.

Total Pageviews

THE BEST QTP TRAINING INSTITUTE IN HYDERABAD

QTP Training in hyderabad

Sql Tutorial

Popular Posts

Our Facebook Page

TrainingHUB

Followers