Column Level Constraint

What are Column Level Constraint and Table Level Constraint? How do they differ from one another?

Questions by ravi.allam9   answers by ravi.allam9

Showing Answers 1 - 12 of 12 Answers

Table Level Constraint

CREATE TABLE supplier_item ( supp_no INTEGER NOT NULL, item_no INTEGER NOT NULL, qty INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (supp_no, item_no) ) ;

In the above example you can see that the table is already created and in the end of the statement we provide the Primary key constraint, So its like creating table and end of the statement we defind the constraint. The Supp_no and item no are primary key defined at last.. That is what Table level constraint is.

And the normally when we are creating the table beside eack column we can mention the constraint indivisually called the column level constraint

Example of Column level constraint

CREATE TABLE supplier_item ( supp_no INTEGER NOT NULL PRIMARY KEY, item_no INTEGER NOT NULL, qty INTEGER NOT NULL DEFAULT 0 ;

  Was this answer useful?  Yes

sravee123

  • Jun 10th, 2008
 

Table level constraint:

Ex: create table emp(empno integer,ename varchar(20),deptno integer,primary key(empno))

column level constraint:

create table emp(empno integer primary key,ename varchar(20),deptno integer)



In table level need create constraint at end of the table, where as in column level need to declare the constraint after the column declaration.

  Was this answer useful?  Yes

katgeektalk

  • Aug 22nd, 2010
 

You can create the constarin at either the column or table level. Constrain defined at the column level are included when the column is defined. Table-level constrains are defined at the end of the table definition and must refer to the column or columns on which the constraint pertains in a set of parentheses.

NOT NULL constrain MUST be defined at the column level.
Constrains that apply to more than one column MUST be defined at the table level.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions