在SQL Server 2014中添加外键
我正在使用SQL Server 2014,在向表中添加外键时遇到问题在SQL Server 2014中添加外键,sql,foreign-key-relationship,sql-server-2014,Sql,Foreign Key Relationship,Sql Server 2014,我正在使用SQL Server 2014,在向表中添加外键时遇到问题 alter table product add FOREIGN KEY (productid) references orderdetail(productid) 我试图在我的product表中添加一个外键,该外键引用另一列productid,该列也可以在orderdetail表中找到,但当我添加外键时,我得到了错误 味精156,第15级,状态1,第46行 关键字“FOREIGN”附近的语法不正确 我可以重写我的
alter table product
add FOREIGN KEY (productid)
references orderdetail(productid)
我试图在我的product表中添加一个外键,该外键引用另一列productid
,该列也可以在orderdetail
表中找到,但当我添加外键时,我得到了错误
味精156,第15级,状态1,第46行关键字“FOREIGN”附近的语法不正确
我可以重写我的语句,但如果我使用addconstraint,它会在关键字constraint附近说不正确的语法。非常感谢您的任何意见 您缺少
约束
:
alter table product
add constraint give_it_a_name_here
FOREIGN KEY (productid)
references orderdetail(productid)