Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreign Key Creation 1

Status
Not open for further replies.

GRHE

Programmer
Jun 19, 2001
29
0
0
GB
Hi All

can you create a foreign key to an existing table that works the same way has having 'Left Outer Join' in a Select statement. So that all rows in table 1 are displayed, even if they don't have a valid key to table2??????????????


TABLE1
TAB1KEY int
TAB2KEY int
CONTENT char

TABLE2
TAB2KEY int
COLOUR char

SELECT TABLE1.TAB1KEY, TABLE1.TAB2KEY, TABLE1.CONTENT, TABLE2.TAB2Key, TABLE2.COLOUR
FROM {TABLE1 TABLE1 LEFT OUTER JOIN TABLE2 TABLE2 ON TABLE1.tab2key = TABLE2.Tab2Key}

Many Thanks
 
When you create a foreign key relationship, all records in the foreign table must have a valid key in the original table. The reverse is not true, you can have records in the original table that do not exist in the foreign table.

However, to see them in a select statment, you still need to use an outer join.
 
Cheers Sis

That's what I thought, but best to check before I went too far ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top