HowTo: Create SQL Table Relationships via Drag´n´Drop

image_thumb3If you create a relationship between to SQL tables, you get many benefits. The most important benefit (for me) is the integrity of your data. Besides the database-world there is another huge benefit: The relationships are used by many O/R mappers to create a structured object model. You could create such realtionships via different dialogs in the SQL Management Studio / Visual Studio or just do a "Drag´n´Drop" from one table to another one.

Relationships & O/R Mappers 
Linq2Sql & ADO.NET Entity Framework are both O/R mappers built in the .NET Framework (but you could use NHibernate or others as well)  and create entities based on a database. If you have relationships in your database, you will find these relationships later in you object model. To create such realationships in you SQL Database you have 2 (or 3) options:

Option A: With dialogs

Select table -> column -> modify:

image_thumb4

*right click* -> Relationships…

image_thumb5

Add -> Tables and Column Specification:

image_thumb7

Select table/column:

image_thumb9

Tada: Relationship created – but you need some clicks to do it. Now option B:

Option B: With an database diagram

image_thumb10

2 tables and the red line marks the relationship we wants to add:

image_thumb13

… just click on the primary key and drag it on the foreign key::

image_thumb16

Now you´ll see a dialog to specify the relationship.

Result:
Option B saves more time and is much more "visual" – option C would be: Write the SQL queries manual.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by Code Inside Team

Currently there is no additional info about this author.

4 Responses

  1. Thanks for this article, I’ve always gone with the visual approach.  Think this is namely due to my bringing up on Microsoft Access which supported the visual approach although it’s good to know how to manually create the relationships.
    Thanks

    Reply
  2. You can also use this simple and easy to use application: http://bstdownload.com/reviews/dbschema-5/

    Reply
  3. That was helpful
    Thanks for your nice working

    Reply

Comment on this post

Recent Posts

  • image1528-570x194_thumb.png
    Introduction to Redis on Windows & Redis usage with .NET

      Redis belongs to the NoSQL data banks and you will find it in the group of Key-Value Stores. Redis is often named “Blazing Fast” and according to the Stackoverflow Thread it is used to be two time (while writing) and three times (while reading) quicker than MongoDB. Even if the comparison is a little ...

  • Automated Security Analyser for ASP.NET websites

    Evil Hackers are lurking everywhere and many Web-applications are delicately and share “too much” with the attacker. A quick (first!) overview offers the Tool “ASafaWeb”. All the website does is making a few requests and writing an Analyses including problem solving’s. There are no permanent disadvantages (bad requests/ DoS attacks and so on). Example: KnowYourStack.com ...

  • image1489-570x194.png
    „Sign in with Twitter“ for your own ASP.NET WebApp

      “Sign in with Twitter” is a popular practice to authenticate the users on your website. One advantage compared to an own registration is the lower inhibition for the user. But on the other hand Twitter doesn’t fess up with all the information’s and you will get into a kind of addiction. At the end ...

  • image1485-570x194_thumb.png
    CodePlex is going to be updated

      CodePlex the Microsoft Open Source Project Hosting Plattform hasn’t changed that much in the last few years and for a few times I thought Microsoft stopped the whole developing process. But now I found out that there is still life in the project. Maybe it is because of the success of GitHub or because ...

  • image1474_thumb.png
    What does Adobe in the flash-free web? Magazine-Style Layouts with CSS Regions!

      Adobe is well known for Photoshop and Flash but of course there is a lot more. According to the “Future Post” from Google Adobe declared one of their big subjects on a Blogpost. I’m talking about the W3C Working Draft to CSS Regions. Adobe cooperates with the WebKit Team and W3C on this. What ...

Support us