Friday, January 7, 2011

Sql Server: Quickest Way to Create Tables Relationship

Creating relationship between tables is not a big task, but I have noticed that many of us (especially I) want to create these relation in minimum time. We can create relations between tables through T-Sql (most time consuming method) or we can complete this task through graphical design view of table in Sql Server Management Studio. But I like to create these relations with following method.
1.  Create table through design view in SSMS (Quick way to create table). In our example we have created following four tables.

2.       Create a database diagram by following method
a.  Right click on “Database Diagram” and click “New Database Diagram”
b.      Add your desired tables. In our case we will add four tables
3.  Click on primary key column and drag it to related table. Verify columns to join in pop-up window and press OK for both pop-up windows. Repeat the process with all table and you are done.

4.       Cltr + S  or click on save button to save diagram and table relations.

6 comments:

  1. very informative. Thanks!

    ReplyDelete
  2. thanks a lot.very helpfull for me

    ReplyDelete
  3. This is fantastic!

    ReplyDelete
  4. Thank you so much for this simple picture! This explains a lot more than any other articles on that issue or any MS Help Topic.

    ReplyDelete
  5. Thank you! So much easier to understand than any of the other articles or videos I've found. Just a couple of clicks and I have my database all set up with relationships.

    ReplyDelete

All suggestions are welcome