SQL - Structured Query Language

Unique Key Constraint



Unique Constraint can define with one column or set of columns that used to identify a Record and to avoid duplicate Records of Table in the Relational Database. Unique Constraint is accepting Null Data. Each Table can define with one or more than one Unique Constraint. Unique Constraint is helps to define Alternative Key.
The following SQL Statements are used to create DEPT and EMP Tables with set of constraints.

-- Sample Statements --

 

CREATE TABLE DEPT

(

Dept_Code numeric(5) Primary Key,

Dept_Name varchar(50) Not Null,

)

GO

 

CREATE TABLE EMP

(

Emp_Code numeric(5)Primary Key,

Emp_Name varchar(50) Not Null,

DOJ datetime Default GetDate(),

Salary numeric(7,2) Check (salary > 1000 and Salary < 5000),

Phone varchar(50),

Dept_Code numeric(5) References DEPT(Dept_Code)

On Delete Cascade

)

GO


More Reference URL: https://data-e-education.com/RDBMS/Key_Integrity_Constraints.php

* * * * *


Email Your Comment To AUTHOR