What is the difference between table-level and column-level?
Any example?The difference is really not functional, except that a "column constraint"
must only reference the column that it is defined along with:
CREATE TABLE x
(
SomeCol VARCHAR(50)
CHECK (SomeCol = 'This is a column constraint'),
SomeOtherCol VARCHAR(50)
CONSTRAINT ck_Named CHECK (SomeOtherCol = 'This is another column
constraint'),
CONSTRAINT ck_named2
CHECK (SomeCol = 'This is a table constraint' OR SomeOtherCol ='This is a table Constraint')
)
... notice that ck_named2 references both columns. This would not be
possible for either of the other constraints.
The other somewhat-functional difference is that column constraints populate
the parent_column_id column of the sys.check_constraints view with their
respective column ID, whereas a table constraint does not...
select name, parent_column_id, definition
from sys.check_constraints
where parent_object_id = object_id('x')
Adam Machanic
SQL Server MVP - http://sqlblog.com
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:%23SbXAKd6HHA.5136@.TK2MSFTNGP02.phx.gbl...
> What is the difference between table-level and column-level?
> Any example?
>
Sunday, March 11, 2012
Check constraints
Labels:
column-level,
constraints,
database,
microsoft,
mysql,
oracle,
server,
sql,
table-level
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment