The main constraint is divided into a primary key, foreign key constraints, unique constraints, check constraint, non-null constraint
Delete index alter table tablename drop constraint contraintname
Create a primary key constraint
If id int primary key identity (1,1) in the construction of the table or constraint pjk_name primary key (id)
Then adding a separate alter table tablename add constraint pk_name primary key (column1, column2)
Create a foreign key constraint
If the constraint foreign key (num) references tablename (columnname) in the construction of the table
单独添加 alter table tablename add constraint fk_name foreign key (num) references tablename2(columnname2)
Create a check constraint
alter table tablename with check | nocheck // This means that when you add a constraint to check whether existing data
add constraint ck check (name<100 and num >0)
Create a unique index
When construction of the table directly unique (num)
Also add alter tablename add uk unique (num)