Create & Drop a Unique Constraint - SQL Query
i) How to create a unique constraint on table student?
The following query will create a unique constraint while creating a table student on column Stud_ID.
CREATE TABLE Students
(
Stud_ID INT not null,
Stud_Name varchar2(50) not null
CONSTRAINT Stud_unique UNIQUE (stud_ID)
);
The above query will create a UNIQUE constraint on the field Stud_ID.
ii) CREATE A UNIQUE constraint using ALTER TABLE statement.
Consider the table 'Students' which is already created so the following query will create a UNIQUE constraint on column Stud_ID.
ALTER TABLE Students
ADD CONSTRAINT Students_unique UNIQUE (Stud_ID);
iii) How to drop a Unique constraint?
The following query will delete a UNIQUE constraint crated on Stud_ID from table Students.
ALTER TABLE Students
DROP CONSTRAINT Students_unique;