开发者

How to add foreign key to already created table

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜