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
how to dump a table to a file with 'mysqldump'? : Sql dba
What is the current version of postgresql?
What is embedded sql what are its advantages?
How do I find duplicates in two columns?
How does rowid help in running a query faster?
Is trigger a stored procedure?
define data blocks ? : Sql dba
What is a full join sql?
What is sql and how does it work?
How do you define a foreign key?
How can we solve sql error: ora-00904: invalid identifier?
Define union, minus, union all, intersect ?
How do I run a query in pl sql developer?
What is difference between hql and native sql?
What is execute immediate?