Tuesday 28 June 2016

How to add Foreign Key in SQL Management Studio

I am going to show you , how to add a Foreign Key to a table from an another table in SQL Management Studio.
When you are dealing with the SQL data base with the .Net technologies , it is very easy to handle your SQL data base using the “SQL Management Studio“.
Lets see how can we do this….
Step 1
  • Go to the table design of selected DB table.
  • then select the attribute which needed to be set as foreign key .
sql_FK1
Step 2
  • Right click and get the menu, then select the “Relationships” from the menu
sql_FK2
  • then new window will appear..
sql_FK3
Step 3
Click on the [+] button under “Table And Columns Specifications” and then again click on the button which is in right side.
sql_FK4then new window will appear…
sql_FK5
Step 4
  • In new window fill needed info related to the FK.
  • Select Primary key table and Its Primary Key attribute.
  • Select the Foreign Key table and Foreign Key attribute.
sql_FK6sql_FK7
Step 5
  • Click OK button in current window and then click Close button in next window.
  • Now you have set Foreign Key to link tow tables.
  • You will see created FK in Keys dialog box also..
sql_FK8
Cheers..!  :-)

No comments:

Post a Comment