我可以通过选择两列(OrderId、CompanyId)并右键单击并设置为主键,在 sql server management studio 2012 中成功创建复合主键。但我不知道如何使用 sql server management studio 2012 在其他表中的两列(OrderId、CompanyId)上创建外键。
在对象资源管理器中,转到您的表并选择Keys > New Foreign Key
从上下文菜单:
From the dialog box that pops up, click on the Add button to create a new foreign key:
Give it a meaningful name and then click on the ... button to open the Tables and Columns specification
dialog box:
Fill in the necessary columns for the parent and the child tables, click OK and you're done!
Or 更轻松、更高效- 使用 T-SQL 脚本!
ALTER TABLE dbo.OtherTable
ADD CONSTRAINT FK_OtherTable_ParentTable
FOREIGN KEY(OrderId, CompanyId) REFERENCES dbo.ParentTable(OrderId, CompanyId)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)