简体   繁体   English

在数据库中创建外键关系

[英]Create foreign key relationship in database

This is most likely a very silly question, I am not a programmer. 这很可能是一个非常愚蠢的问题,我不是程序员。

I have used visual studio to create a database for my application. 我已经使用Visual Studio为我的应用程序创建数据库。

The table "CapitalPlan" has primary key "ProgramID" - this needs to be the foreign key in table "MilestoneData" field "ProgramID" 表“ CapitalPlan”具有主键“ ProgramID”-这需要作为表“ MilestoneData”字段“ ProgramID”中的外键

Can anyone please advise how I set up the "ProgramID" in "MilestoneData" to be a foreign key? 谁能建议我如何在“ MilestoneData”中设置“ ProgramID”作为外键?

Image shows where I'm currently at (not very far!) 该图显示了我目前所在的位置(不远!)

Much appreciated! 非常感激!

image: http://i1186.photobucket.com/albums/z373/barbsbargainsltd/cDatabase_zps52ddc806.jpg 图片: http : //i1186.photobucket.com/albums/z373/barbsbargainsltd/cDatabase_zps52ddc806.jpg

Under each table (Milestone Data in your case) in designer you have a 'folder' named Keys . 在设计器的每个表(您的情况下为里程碑数据)下,都有一个名为Keys的“文件夹”。 If you right click it, there is a New Foreign Key... option. 如果右键单击它,则有一个New Foreign Key...选项。 Clicking it opens a dialog for you with numerous properties of the foreign key being created. 单击它会为您打开一个对话框,其中包含要创建的外键的许多属性。 You need an ellipsis on Tables And Columns Specification there - it opens a new dialog, allowing to adjust source and destination tables as well as key mapping. 您需要在其中的“ Tables And Columns Specification使用省略号-它会打开一个新对话框,允许您调整源表和目标表以及键映射。

This way is applicable for SQL Server Management Studio, but the image you provided suggests that the solution for VS should be identical. 这种方法适用于SQL Server Management Studio,但是您提供的映像表明VS的解决方案应该相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM