SQL server 添加主外鍵約束

---添加主鍵約束            sql

 

alter table 表名      server

add constraint 約束名 primary key (主鍵)          -get

 

--添加惟一約束           

 

alter table 表名              table

add constraint 約束名 unique (字段)       im

 

---添加默認約束          

 

alter table 表名         數據

add constraint 約束名 default ('默認內容') for 字段             tab

 

--添加檢查check約束,要求字段只能在1到100之間             

 

alter table 表名 di

add constraint 約束名 check (字段 between 1 and 100 )        co

      

---添加外鍵約束(主表stuInfo和從表stuMarks創建關係,關聯字段爲stuNo)    

        

alter table 從表              block

add constraint 約束名 <br>   foreign key(關聯字段) references 主表(關聯字段)      

     

sql server中刪除約束的語句是:          

 

alter table 表名 drop constraint 約束名             

sp_helpconstraint 表名 找到數據表中的全部列的約束           

相關文章
相關標籤/搜索