Table Level Constraints

Here constraints are going to be placed on columns after the definition of all columns and their corresponding data types.It means at the end of the table definition constraints will be placed on columns.

Note:In Table Level constraints DEFAULT and NOT NULL constraints are not allowed.

Syntax:(With out Constraints names)

CREATE TABLE TABLENAME (COLUMN1 DATATYPE,COLUMN2 DATATYPE,.....CONSTRAINT TYPE (COLUMN1),CONSTRAINT TYPE (COLUMN2),.............)

Example1: CREATE TABLE DEPT (DEPTNO INT,DNAME VARCHAR(20),LOC VARCHAR(20),PRIMARY KEY (DEPTNO),UNIQUE (DNAME))

Syntax: (With Constraint names)

CREATE TABLE TABLENAME (COLUMN TABLE TABLENAME (COLUMN1 DATATYPE,COLUMN2 DATATYPE,.... CONSTRAINT CONSTRAINTNAME CONSTRAINT TYPE (COLUMN1),CONSTRAINT CONSTRAINTNAME CONSTRAINT TYPE (COLUMN2),.....................)

Example1:

CREATE TABLE DEPT (DEPTNO INT,DNAME VARCHAR(20),LOC VARCHAR (20),CONSTRAINT PK PRIMARY KEY (DEPTNO),CONSTRAINT UQ UNIQUE (DNAME))
Share/Bookmark

No comments: