HowTo: Create SQL Table Relationships via Drag´n´Drop
If 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:
*right click* -> Relationships…
Add -> Tables and Column Specification:
Select table/column:
Tada: Relationship created – but you need some clicks to do it. Now option B:
Option B: With an database diagram
2 tables and the red line marks the relationship we wants to add:
… just click on the primary key and drag it on the foreign key::
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.



James Radford
September 4, 2009
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
florin
April 27, 2011
You can also use this simple and easy to use application: http://bstdownload.com/reviews/dbschema-5/
Arash
June 16, 2011
That was helpful
Thanks for your nice working
Karl Rakestraw
July 5, 2012
Appreciate your spending some time to talk about this specific, I feel firmly over it and also actually like reading through on this kind of topic.
Alishia Graner
August 3, 2012
Incredible ! Outstanding in depth tutorial. I’ll make use of that can ! tm unifi
graphic design gallery
October 7, 2012
You just gained a new brand new audience
Amazon.com Hot New Releases!
January 2, 2013
Outstanding bit of details!