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?
>
Showing posts with label table-level. Show all posts
Showing posts with label table-level. Show all posts
Sunday, March 11, 2012
Check constraints
Labels:
column-level,
constraints,
database,
microsoft,
mysql,
oracle,
server,
sql,
table-level
Thursday, March 8, 2012
Check Constraint
What is the difference in table-level and column-level check constratint?
Any example?Sorry, I forgot had posted here before.
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:%23Hf4Hd26HHA.4584@.TK2MSFTNGP03.phx.gbl...
> What is the difference in table-level and column-level check constratint?
> Any example?
>|||A table level constraint is a Primary Key, or a Foreign key.
A column level constraint could be as simple as NOT NULL, or a CHECK clause
(CHECK _col IN ('Y', 'N'))
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:%23Hf4Hd26HHA.4584@.TK2MSFTNGP03.phx.gbl...
> What is the difference in table-level and column-level check constratint?
> Any example?
>
Any example?Sorry, I forgot had posted here before.
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:%23Hf4Hd26HHA.4584@.TK2MSFTNGP03.phx.gbl...
> What is the difference in table-level and column-level check constratint?
> Any example?
>|||A table level constraint is a Primary Key, or a Foreign key.
A column level constraint could be as simple as NOT NULL, or a CHECK clause
(CHECK _col IN ('Y', 'N'))
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:%23Hf4Hd26HHA.4584@.TK2MSFTNGP03.phx.gbl...
> What is the difference in table-level and column-level check constratint?
> Any example?
>
Labels:
column-level,
constraint,
constratint,
database,
microsoft,
mysql,
oracle,
server,
sql,
table-level
Subscribe to:
Posts (Atom)