SQL - Structured Query Language

Primary Key Constraint



Primary Key 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. Primary Key Constraint must define with Unique, Never Update, Not Null and Sequence Numeric Data Column. Each Table can define with one Primary Key Constraint.

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