October 6, 2003 at 11:36 am
Hello...Can anybody tell me the differences between Column Constraint and Table Constraint? Thanks in advance.
October 6, 2003 at 12:15 pm
A column constraint is specified as part of a column definition and applies only to that column.
A table constraint is declared independently from a column definition and can apply to more than one column in a table. Table constraints must be used when more than one column must be included in a constraint.
Edited by - allen_cui on 10/06/2003 12:15:37 PM
October 7, 2003 at 12:19 am
Taken from BOL.
A table constraint is declared independently from a column definition and can apply to more than one column in a table.
Table constraints must be used when more than one column must be included in a constraint.
For example, if a table has two or more columns in the primary key, you must use a table constraint to include both columns in the primary key. Consider a table that records events happening in a computer in a factory. Assume that events of several types can happen at the same time, but that no two events happening at the same time can be of the same type. This can be enforced in the table by including both the type and time columns in a two-column primary key.
CREATE TABLE factory_process
(event_type int,
event_time datetime,
event_site char(50),
event_desc char(1024),
CONSTRAINT event_key PRIMARY KEY (event_type, event_time) )
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply