更新时间:2023-01-30 11:57:17
在对象资源管理器中,转到您的表并选择 Keys >上下文菜单中的新外键
:
In Object Explorer, go to your table and select Keys > New Foreign Key
from the context menu:
在弹出的对话框中,点击Add按钮来创建一个新的外键:
From the dialog box that pops up, click on the Add button to create a new foreign key:
给它一个有意义的名字,然后点击...按钮打开Tables and Columns Specification
对话框:
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!
或者更简单、更高效 - 使用 T-SQL 脚本!
Or much easier and more efficiently - use a T-SQL script!
ALTER TABLE dbo.OtherTable
ADD CONSTRAINT FK_OtherTable_ParentTable
FOREIGN KEY(OrderId, CompanyId) REFERENCES dbo.ParentTable(OrderId, CompanyId)