开发者

How to add foreign key to already created table

开发者 https://www.devze.com 2023-04-10 13:23 出处:网络
I have created 2 table.Brand and Product.In both table one id is primary key and it has identity.According to foreign key constrain,it should be primary ke开发者_如何学运维y of another table.I want to

I have created 2 table.Brand and Product.In both table one id is primary key and it has identity.According to foreign key constrain,it should be primary ke开发者_如何学运维y of another table.I want to make Brandid as fk of table Product.How to do that.I have alreadyt created table.I am using sql server 2005.

Brand:
id : -primary key,identity
name
lname

Product :
id  :- primary key,identity
location
Brandid (id of Brand table)


Use [db_name] 
Go
alter table Product
add constraint Product_brandid_fk FOREIGN KEY ( Brandid ) references Brand(id)


ALTER TABLE PRODUCT
ADD FOREIGN KEY (brandid) REFERENCES BRAND(id)
0

精彩评论

暂无评论...
验证码 换一张
取 消