Adding UNIQUE Constraints in table:
CREATE TABLE Course(id int UNIQUE, Course_name nvarchar(20));
UNIQUE allow only distinct value in database table. It used to avoid redundant information in table. It allow NULL value for unknown data.
How to add UNIQUE Constraints:
CREATE TABLE Employee(id int UNIQUE, Emp_name nvarchar(20));
In this statement the id is unique value, ie value can't be repeated
Field | Data Type | Null | key | Default |
id | INT | NO | UNIQUE | |
emp_name | NVARCHAR(18) | NO | |
Field | Data Type | Null | key | Default |
id | INT | UNIQUE | ||
course_name | NVARCHAR(20) | |
UNIQUE using ALTER
CREATE TABLE Employee(id int, emp_name nvarchar(20),Age int, dept_id int)
Field | Data Type | Null | key | Default |
id | INT | |||
emp_name | NVARCHAR(20) | | ||
Age | INT | |||
Dept_id | INT |
ALTER TABLE Employee ADD UNIQUE(ID); for MSSQL Server, Oracle, Access.
Field | Data Type | Null | key | Default |
id | INT | UNIQUE | ||
emp_name | NVARCHAR(20) | | ||
Age | INT | |||
Dept_id | INT |
To add UNIQUE to Multiple Column.
ALTER TABLE Employee ADD UNIQUE(Emp_name, age); for MSSQL Server, Oracle, Access.
Field | Data Type | Null | key | Default |
id | INT | UNIQUE | ||
emp_name | NVARCHAR(20) | UNIQUE | | |
Age | INT | UNIQUE | ||
Dept_id | INT |
Thank You. Like, Share and Subscribe 👍 Followlect.com
Comments
Post a Comment