UNIQUE Constraint
ALTER TABLE [TABLENAME] ADD CONSTRAINT [CONSTRAINTNAME] UNIQUE([COLUMNNAME])
CHECK Constraint
ALTER TABLE [TABLENAME] WITH NOCHECK ADD CONSTRAINT [CONSTRAINTNAME] CHECK (([COLUMNNAME] IS NOT NULL))
DEFAULT constraint
ALTER TABLE [TABLENAME] ADD CONSTRAINT [CONSTRAINTNAME] DEFAULT (CONVERT([datetime],CONVERT([varchar],getdate(),(101)),(0))) FOR [COLUMNNAME]
NOT NULL constraint
ALTER TABLE [TABLENAME] ALTER COLUMN [COLUMNNAME] <data_type> NOT NULL
FOREIGN KEY constraint
ALTER TABLE [TABLENAME] WITH CHECK ADD CONSTRAINT [CONSTRAINTNAME] FOREIGN KEY([COLUMNNAME])
REFERENCES [PrimaryTableName] ([PKcolumn])
PRIMARY KEY constraint
Specify fields that uniquely identify each record in the table.
No comments:
Post a Comment