The column constraints apply to the single column within a single base table are the syntax
Column constraints apply to the single column within a single base table are the syntax
column - name {data - type | domain}
[DEFAULT {literal| niladic -functiona | NULL]
[column -constraint - definition - list]
Here the'column constraint -definition -list' specifies the column constraint. A column_constraint definition can be any of the following:-
➡️NOT NULL
➡️PRIMARY KEY or UNIQUE
➡️A 'references definition'
➡️A 'CHECK constraint' definition
The RDBMS automatically evaluates the check constraints expression whenever an SQL INSERT, UPDATE or DELETE statement is executed.If the evaluation of the CHECK constraint is true,then the update is allowed otherwise the data in the table remain unaltered.
CREATE TABLE EMPLOYEE
(EPNO NUMERIC (4) NOT NULL,
EMPID CHAR (3),
NAME CHAR (30) NOT NULL,
DEPTID CHAR (2) NOT NULL WITH DEFAULT,
BONUS NUMERIC (6,2) NOT NULL,
CHECK (BONUS BETWEEN 4000.00 AND 10000.00),
PRIMARY KEY (EMPNO),
UNIQUE (EMPID),
FOREIGN KEY (DEPTID) REFERENCE DEPARTMENT (DEPTID);
The four cases of column constraints:-
✍️The first column (also third,fourth and fifth) uses the 'NOT NULL' column constraint.
✍️The CHECK constraint is used to enforce the condition that the bonus should between 4000 and 10000.
✍️The 'PRIMARY KEY' and ' clauses are used to define the primary key and alternate key constraints.
✍️The 'FOREIGN KEY ... REFERENCES ...' option is used to define the foreign key constraint.
Comments
Post a Comment