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
 How to use Joins in SQL

Author  Topic 

sruvee
Starting Member

2 Posts

Posted - 2007-10-12 : 14:31:00
Hi,

I understand that An inner join's ON condition retrieves only those records that satisfy the join condition. An outer join does the same thing but with the addition of returning records for one table in which there were no matching records in the other table.

Suppose I write the following Query,
SELECT Customers.CustomerID, Customers.CompanyName, Orders.OrderID
FROM Customers LEFT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerID


Do I need to declare the CustomerID as a Primary Key?

Is there any relation between Joins and Primary key declarations?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-12 : 14:35:24
Joins do not require that the columns in the ON condition have constraints on them (PK or FK). You are almost always joining on columns that are involved in a relationship though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sruvee
Starting Member

2 Posts

Posted - 2007-10-12 : 15:00:12
How can I create database diagrams depending on Joins? I mean, is it possible to create database diagrams (to show relations between tables) for tables which don't have any Primary keys or FK relation ships?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-12 : 15:01:02
I don't know of a tool that can do that. I only know how to create ERDs when PKs and FKs exist.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -