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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 derived tables

Author  Topic 

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-09-20 : 21:51:27
Hello,

I am making a derived table of the form

(select col1, col2
from tablea,tableb, tablec
where table1.foreign key = table2.pk
and table2.pk = table3.fk)) a

join table 3
join table 2

How would I select the key for the derived table?

What should we keep in mind while selecting the key for the derived table?

Thank you!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-20 : 23:30:27
Not sure what you mean. Derived tables can not have a primary key or constraints or anything like that. Of course, as the developer and the person who understands your data, you should be aware of what would be the logical key - ie what columns represent a unique row.

Also, use the ANSI JOIN syntax. ie: INNER JOIN, LEFT OUTER JOIN, etc. The comma seperated list of tables is old school and won't even be supported later.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-21 : 01:28:22
quote:
Originally posted by sqlclarify

Hello,

I am making a derived table of the form

(select col1, col2
from tablea,tableb, tablec
where table1.foreign key = table2.pk
and table2.pk = table3.fk)) a

join table 3
join table 2

How would I select the key for the derived table?

What should we keep in mind while selecting the key for the derived table?

Thank you!



the key column by which you want to join the derived table to other table(s) should be included in select list of derived table.Regarding what column to be chosen as key, it purely based on how rest of query is related to derived table.
Go to Top of Page
   

- Advertisement -