T-SQL to add, delete constraint method

--- add a primary key constraint

alter table table name

add constraint constraint name primary key (primary key) 


- Adding a unique constraint

alter table table name

add constraint constraint name unique (field)


--- add a default constraint

alter table table name

add constraint constraint name default ( 'default content') for field


- add a check check constraint, between 1 and 100 only requires the field to

alter table add constraint constraint name table name check (field of between 1 and 100)


--- add foreign key constraint (stuInfo primary table from the table and the relationship stuMarks, the associated field is stuno) 
ALTER Table Table

add constraint constraint name
foreign key (associated field) references the primary table (associated field) 

 

--sql server delete the constraint statement is:

alter table table name drop constraint constraint name

 

- Find bound by all the columns in the data table

 

sp_helpconstraint SQL Server table name to add, delete constraint method

Guess you like

Origin www.cnblogs.com/zachchen/p/11275050.html