Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Relationships and joins

Author  Topic 

gregevans
Starting Member

1 Post

Posted - 2011-11-19 : 16:33:59
Hello, I have searched far wide on two topics, with no luck.

The two topics are

a) Relationships
b) Joins (Inner joins and cross joins etc)

I understand that creating a join, creates a link between
two tables, based on a condition. (I suspect this creates a recordset
of both tables, that a query works against)

Q. I suspect a Join, doesnt change the structure of a database,
whereas a relationship would? (what does this mean?)

Q. If you have a join, do you still need relationships?

Q. If you have a relationship, do you still need joins?

Q. Instead of a join, can you just create a WHERE clause against
one of the tables, defined in a relationship. Because the relationship
ties two tables together, does a query work accross both tables, defined
in a relationship.

For example, if a relationship ties two tables together, does an INSERT
SQL action, on the first table, update the second table automatically.
Would you use a join to do this or a relationship action.



Greg

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-19 : 17:26:07
Relationships and joins, while related, are two different topics.

Q. I suspect a Join, doesnt change the structure of a database,
whereas a relationship would? (what does this mean?)

A. A relationship is an object (a foreign key) that is stored in the database. A join is simply part of a query. DML queries don't change the structure of a database.

Q. If you have a join, do you still need relationships?

A. Absolutely

Q. If you have a relationship, do you still need joins?

A. Absolutely. A relationship can't bring back records from multiple tables for you. Only a Join can.

Q. Instead of a join, can you just create a WHERE clause against
one of the tables, defined in a relationship. Because the relationship
ties two tables together, does a query work accross both tables, defined in a relationship.

A. Nope. Need to explicitly join the tables if you wish to retrieve records from both.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-19 : 17:27:56
Further reading:

Relationships -- http://msdn.microsoft.com/en-us/library/ms175464.aspx

Joins -- http://msdn.microsoft.com/en-us/library/ms191517.aspx
Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-11-21 : 05:19:12
when there are a relationship between 2 tables so you can use an inner or outer join as a result of that ,So there are integration not Contradiction among them ,For example if you insert into one table join another table no utomatic update happened but if constraints so i can't delete from one depending on another ,So at insert i should insert at 2 tables at same time
Go to Top of Page
   

- Advertisement -