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 sql exception?

731


How can a pl sql block be executed?

703


What is partition by in sql?

807


What are the types of queries in sql?

757


Table A Table B 1 1 2 1 3 1. Union & union all --> A Union B , A Union all B 2. Minus , Intersect --> A minus B , B Minus A , A Intersect B 3. Joins A join B , A Left Join B A Right Join B , A full Join B 4. %Type - Uses & Benifit 5. Truncate & Delete 6. Pragma Autonomus Transaction 7. how to Perform DDL from function or procedure 8. Can we have DML inside Function 9. Rank & Dense Rank diffrence 10. Water Mark in Oracle 11. Index , Can we have index in all column of table if no then why ?

756


What is trigger point?

750


What is the difference between row level and statement level trigger?

742


Does a user_objects view have an entry for a trigger?

783


What is self-join and what is the requirement of self-join?

873


What are the different types of dbmss?

765


Is sql easier than java?

755


What is sqlca in db2?

712


What is right join sql?

726


What is the location of pre_defined_functions.

867


What is the starting oracle error number? What is meant by forward declaration in functions?

756