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 2000 Forums
 SQL Server Development (2000)
 Problem in accessing subclasses

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-27 : 20:53:17
Jain writes "I have the following relational schema:
Table_A(time_stamp,A_var,prim_key_B)

Table_B(prim_key_B,B_name)

Table_C(prim_key_B,C_var1,C_var2)

Table_D(prim_key_B,D_var1,D_var2)

time_stamp is primary key for Table_A
prim_key_B is primary key for Table_B,C,D

Table_B is superclass with Table_C and Table_D as its subclasses.
prim_key_B, which is an autogenerated key, links Table_A with Table_B.
B_name has values(CHAR) which are exactly same as the name of Table_C and Table_D.

My requirement is following:
I want to display all the attributes of Table_A, B_name, and all the attributes of the related subclass.

I am facing problem in locating the right subclass although from B_name I know the name of the subclass to refer.Could you please send me the SQL query for the above requirement.

Thanks in advance!"

Nazim
A custom title

1408 Posts

Posted - 2002-01-28 : 00:48:39
IMHO, You have a poorly designed database.

when you have stated that prim_key_B links the table , why should you locate for B_name?.

quote:

Table_B is superclass with Table_C and Table_D as its subclasses.
prim_key_B, which is an autogenerated key, links Table_A with Table_B.
B_name has values(CHAR) which are exactly same as the name of Table_C and Table_D.


I am facing problem in locating the right subclass although from B_name I know the name of the subclass to refer




Anywayz , Hope this query does what you are looking for
select b.Prim_key_B,a.time_stamp,a.b_name,c.C_var1,c.C_var2,D.D_Var1,D._var2
from Time_B a left join
Time_A b
on a.prim_key_b=b.prim_key_b
left join time_C c
on a.prim_key_b=c.prim_key_b --or b_name with either c_var1 or c_var2
left join time_d d
on on a.prim_key_b=d.prim_key_b --or b_name with either d_var1 or d_var2

Post your requirements with your other table schema's . we will try to assist you in your design changes.

--------------------------------------------------------------
Dont Tell God how big your Problem is , Tell the Problem how Big your God is

Edited by - Nazim on 01/28/2002 00:50:32
Go to Top of Page
   

- Advertisement -