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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

define sql update statement ? : Sql dba

584


What is difference between primary and secondary key?

519


What is graph sql?

528


what does the t-sql command ident_incr does? : Transact sql

606


What is query execution plan in sql?

571






Difference between global and parameter variables?

1462


Show code of a cursor for loop.

584


what is auto increment? : Sql dba

577


How to fetch values from testtable1 that are not in testtable2 without using not keyword?

759


What is sql query optimization?

549


Is coalesce faster than isnull?

512


What is 19 null in sql?

536


How do you declare a variable in pl sql?

535


How many commands are in sql?

529


What are conditional predicates?

589