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

Answers were Sorted based on User's Feedback



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

Answer / santosh kumar

Let me explain both sides of the coin bit more clearly.

Table level Constraint
===========================
1. Constraints are defined separately after the columns are defined.
2. While defining constraints at this level constraint name must be provided
3. Not null constraints can't be defined at this level.
4. Composite keys can be defined at this level only.

A table level constraint can see every column in the table.


Column level Constraint
===========================
1. Constraints are defined along with the columns.
2. So constraint name is not required.
3. Not null constraints can be defined at this level only(NOT NULL constraint can only apply to one column).
4. Composite keys can't be defined at this level .
5. Column level constraint is more clear syntactically and more meaningful.

A column level constraint has scope only to the column it is defined on.


The major difference between the two constraint is the scope. So far as the use of constraints (validating proper data) is concerned they are pretty much the same.


Any column level constraint (exception: not null) can be expressed at the table level - but the opposite is not true.
Go for a column level constraint if the constraint is in fact a column constraint else use a table constraint.

It is recommended to always use a column constraint if the constraint applies just to the column (and NOT a table constraint if it only applies to a single column) - you can only do it at the column level.

Is This Answer Correct ?    6 Yes 0 No

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

Answer / 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

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

Answer / selvi

Column level constraint can not refer other columns or sysdate, UID, currVal, nextVal or rownum, and this is limitation of column level constraint over table level constraint.

Is This Answer Correct ?    1 Yes 2 No

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

Answer / sravya

column level contains only one column whereas tablelevel contains group of columns

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL PLSQL Interview Questions

how many ways we can we find the current date using mysql? : Sql dba

0 Answers  


What is a schema? How is it useful in sql servers?

0 Answers  


what are the properties and different types of sub-queries? : Sql dba

0 Answers  


what are numeric data types? : Sql dba

0 Answers  


what is overloading procedure or overloading function ?

3 Answers   Genpact,






How do you retrieve set of records from database server. {Set max records = 100 & use paging where pager page no or records = 10 & after displaying 100 records again connect to database retrieve next 100 }

2 Answers   DELL,


how to implement one-to-one, one-to-many and many-to-many relationships while designing tables? : Sql dba

0 Answers  


When we can declare a column as Unique and Not Null both at the same time. What is the use pf Primary Key then?

2 Answers   Accenture, Unisoft Infotech,


Which one is the Best approach to put code, among Triggers and Procedures? Explain?

1 Answers   Sierra Atlantica,


What is the default isolation level in sql server? : Transact sql

0 Answers  


What is database sql?

0 Answers  


What are the various restrictions imposed on view in terms of dml?

0 Answers  


Categories