唯一:ALTER TABLE TableName ADD CONSTRAINT UQ_NickName UNIQUE(NickName)

主键:ALTER TABLE TableName ADD CONSTRAINT PK_ID PRIMARY KEY(ID)

默认值:ALTER TABLE TableName ADD CONSTRAINT DF_Gender DEFAULT ('男') FOR Gender

check:ALTER TABLE TableName ADD CONSTRAINT CK_Age CHECK(Age>0)

外键:ALTER TABLE TableName ADD CONSTRAINT FK_ParentID FOREIGN KEY(ParentID) REFERENCES ParentTableName(ID)

移除约束:

ALTER TABLE [dbo].[S_USER] DROP CONSTRAINT UQ_U_NAME

sp_helpconstraint 表名 找到数据表中的所有列的约束

05-11 22:04