difference between table level constraint and column level and
advantages of table level constraint

Answer Posted / anil

ANS:
COLUMN LEVEL CONSTRAINT
If we provide constraint along with column while creating the table then it is column level constraint. For column level constraint a constraint name is not mandatory.

TABLE(ROW) LEVEL CONSTRAINT
If we provide constraint after providing all the columns then it is table level constraint.For table level constraint a constraint name is mandatory.

Advantage of table level constraint:
We can create composite PK and composite FK in table level constraints but we cant create these in column level constraints.

Example:
CREATE TABLE oracle_tab
(
ord_id  NUMBER,
pid NUMBER,
qty NUMBER(2),
ord_dt DATE NOT NULL, /*column level constraint(cant be created as table level constraint)*/
price NUMBER(9,1) DEFAULT 0, /*column level constraint(cant be created as table level constraint)*/
CONSTRAINT ord_pk PRIMARY KEY(ord_id,pid), /*table level(can be created either as table level constraint or column level)*/
CONSTRAINT ord_fk FOREIGN KEY(pid) REFERENCES products(pid),/*table level(can be created either as table level constraint or column level)*/
CONSTRAINT ord_ch CHECK(qty>0) /*table level(can be created either as table level constraint or column level)*/
);

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the difference between ereg_replace() and eregi_replace()? : Sql dba

545


Where is pl sql used?

512


What is t sql used for?

544


What is the basic form of sql query?

485


How to convert comma separated string to array in pl/sql?

588






Why function is used in sql?

510


what is union? : Sql dba

573


How can one get sql*loader to commit only at the end of the load file? : aql loader

557


What are sql*plus environment variables?

546


What does inner join mean?

545


What is a file delimiter?

550


What are the main features of cursor?

617


What sql does db2 use?

533


What is procedure in pl sql?

526


what happens if null values are involved in expressions? : Sql dba

557