无法创建Sql外键 [英] Unable to Create Sql Foreign key

查看:127
本文介绍了无法创建Sql外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了1张桌子
我将其命名为ItemMaster,他们创建了2个主键
在Sql2008中(itm_grp_id和item_id)
n第二次创建另一个表让我们说tblOpeningClosing
因为它们是字段item_id
我想在此表上添加一个外键

I have created 1 table
name as ItemMaster their I have created 2 Primary Keys
in Sql2008 (itm_grp_id and item_id)
n Second time I have Created another table Lets say tblOpeningClosing
in that their is field item_id
I Want To Add One Foreign Key on this table

alter table dbo.tblClosingStock
add Foreign Key (item_code)
References dbo.tblItemMaster(item_code)


它不起作用


Its not working

There are no primary or candidate keys in the referenced table 'dbo.tblItemMaster' that match the referencing column list in the foreign key 'FK__tblClosin__item___531856C7'.

推荐答案

alter table dbo.tblClosingStock
add Foreign Key (item_code)
References dbo.tblItemMaster(item_code)




在tblItamMaster表中,您已将主键分配给item_code.
检查.!




In tblItamMaster table you have assign primary key to item_code.
Check that.!


这篇关于无法创建Sql外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆