WHAT IS CONSTRAINTS ? DIFFERENT TYPES OF CONSTRAINTS?

Sriramnandha
Posted by Sriramnandha under Sql Server category on | Points: 40 | Views : 4365
CONSTRAINTS PROVIDE A MECHANISM PROVIDE INTEGRITY IN THE DATABASE.THERE ARE THREE TYPES OF CONSTRAINTS IN SQL SERVER.

TO CREATE A TABLE BEFORE WE HAVE TO CHECK CONDITION.THERE ARE THREE TYPES OF CONSTRAINT IN SQL SERVER

1) DOMAIN INTEGRITY CONSTRAINT.
2 ENTITY INTEGRITY CONSTRAINT.
3) REFERENTIAL INTEGRITY CONSTRAINT.

DOMAIN INTEGRITY CONSTRAINT:

1) NOT NULL
2) CHECK

NOT NULL:
CREATE TABLE EMP(EMPID INT CONSTRAINT PK_EMPID NOT NULL,EMPNAME VARCHAR(90))


CHECK:


CREATE TABLE EMP(EMPID CONSTRAINT PK_EMPID CHECK (EMPID<100))


ENTITY INTEGRITY CONSTRAINT:

1) PRIMARY KEY CONSTRAINT
2) UNIQUE KEY CONSTRAINT

PRIMARY KEY:

PRIMARY KEY RESTRICT DUPLICATE VALUES AND NULL VALUES

CREATE TABLE EMP(EMPID INT CONSTRAINT PK_EMPID PRIMARY KEY(EMPID), EMPNAME VARCHAR(90))


UNIQUE KEY:

UNIQUE KEY RESTRICT DUPLICATE VALUES AND ALLOW ONE NULL VALUES


CREATE TABLE EMP(EMPID INT CONSTRAINT PK_EMPID UNIQUE(EMPID), EMPNAME VARCHAR(90))


REFERENTIAL INTEGRITY CONSTRAINT:

PARENT TABLE CHILD TABLE RELATIONSHIP

PARENT TABLE:
CREATE TABLE EMP(EMPID INT CONSTRAINT PK_EMPID PRIMARY KEY(EMPID),EMPNAMEE VARCHAR(90))


CHILD TABLE

CREATE TABLE EMPLIST(EMPID INT REFERENCES EMP(EMPID),EMPSALARY MONEY)


REGARDS

Comments or Responses

Login to post response