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
where are cookies actually stored on the hard disk? : Sql dba
Why is sql important?
How do I edit a trigger in sql developer?
i have a column which may contain this kind of value: 123*67_80,12*8889_5,34*8_874 ,12*7_7 (can contain space before a comma, and this string length can be anything) now i want to split this value into two column like: column1: 123*67,12*8889,34*8,12*7 column2: 80,5,874,7 use function for this
What is secondary key?
What are the key differences between SQL and PL SQL?
What are the methods of filing?
can a stored procedure call itself or recursive stored procedure? How much level sp nesting is possible? : Sql dba
Why indexing is needed?
define sql insert statement ? : Sql dba
What is record type in pl sql?
What is an implicit commit?
What is sql profiling in oracle?
what is difference between delete and truncate commands? : Sql dba
How to know the last executed procedure?