PC Review


Reply
Thread Tools Rate Thread

Auto-joining tables

 
 
David Thielen
Guest
Posts: n/a
 
      10th Jul 2009
Hi;

We are using the PK:FK metadata to automatically join tables. However,
we are hitting a problem. In some cases when combining 3 or more
tables we don't have a single direct path through all the tables. So
we end up joing table_1 to table_2, and then in joining table_3 we go
part way back down the joins between 1 & 2.

Is there a suggested best approach to how to take all the needed join
trails and build up a join between all of them?

thanks - dave

david@at-at-(E-Mail Removed)
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Reply With Quote
 
 
 
 
Colbert Zhou [MSFT]
Guest
Posts: n/a
 
      13th Jul 2009
Hi Dave,

Could you please elabrate the scenario? Based on my understanding, you are
creating an application that can parse the database' metadata and
illustrate them in your own UI, right? So the application acts like the
Visual Studio's Query and View Designer. But we encounter problem when the
relationship exists for 3 or more tables, right? If so, would you mind
sharing the DataTable's schema?

And if we add these three tables to Visual Studio Query and View Designer,
does the diagram generates OK? Any screenshot to show the problem
intuitively will be helpful.


Best regards,
Colbert Zhou
Microsoft Newsgroup Support Team

 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      13th Jul 2009
On Mon, 13 Jul 2009 09:57:13 GMT, (E-Mail Removed)
(Colbert Zhou [MSFT]) wrote:

>Hi Dave,
>
>Could you please elabrate the scenario? Based on my understanding, you are
>creating an application that can parse the database' metadata and
>illustrate them in your own UI, right? So the application acts like the
>Visual Studio's Query and View Designer. But we encounter problem when the
>relationship exists for 3 or more tables, right? If so, would you mind
>sharing the DataTable's schema?
>
>And if we add these three tables to Visual Studio Query and View Designer,
>does the diagram generates OK? Any screenshot to show the problem
>intuitively will be helpful.


Lets say I have these relationships:

Table1 - Table2
Table2 - Table3
Table2 - Table4

In my select I am using Table1, Table3, & Table4. So I need to join:

Table1 -> Table2 -> Table3
and
Table1 -> Table2 -> Table4

What we are presently doing (because we just build it up in order of
use) - this works but is ugly & possibly inefficient:

Table1 -> Table2 -> Table3 -> Table2 -> Table4

I'm wondering if there is a better way to build up the inner joins in
the select.

Note - the relationships all show correctly. The question is how to
write the inner join across all of them.

thanks - dave

david@at-at-(E-Mail Removed)
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Reply With Quote
 
Colbert Zhou [MSFT]
Guest
Posts: n/a
 
      16th Jul 2009
Hi,

I am sorry I still do not catch you very well, I think. Could you please
let me know if my understanding in the first reply is right? Do you mean
you are creating your own designer of SQL table relationships? And is the
graphic in Visual Studio or SQL Management Sutdio generated as expected? If
this is case, I think it is only related how we design the drawing
algorithm based on the retrieved schema. We need to write an algorithm that
can detect and avoid the duplicated table in multiple relationships.

If your question is only regarding how to do multiple inner joins, I think
we just write SQL commands like this,

Select [Orders].OrderID ,
[Order Details].Discount,
[Customers].CustomerID ,
[Shippers].ShipperID ,
[Shippers].CompanyName
from
[Orders] inner join [Order Details] on [Orders].OrderID = [Order
Details].OrderID
inner join [Customers] on [Orders].CustomerID = [Customers].CustomerID
inner join [Shippers] on [Orders].ShipVia = [Shippers].ShipperID

I use Northwind as the test database, here Order Details is Table1, Orders
is Table2, Customers is Table3, Shippers is Table4


Best regards,
Colbert Zhou
Microsoft Online Support Team

 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      16th Jul 2009
On Thu, 16 Jul 2009 08:19:43 GMT, (E-Mail Removed)
(Colbert Zhou [MSFT]) wrote:

>Hi,
>
>I am sorry I still do not catch you very well, I think. Could you please
>let me know if my understanding in the first reply is right? Do you mean
>you are creating your own designer of SQL table relationships? And is the
>graphic in Visual Studio or SQL Management Sutdio generated as expected? If
>this is case, I think it is only related how we design the drawing
>algorithm based on the retrieved schema. We need to write an algorithm that
>can detect and avoid the duplicated table in multiple relationships.
>
>If your question is only regarding how to do multiple inner joins, I think
>we just write SQL commands like this,
>
>Select [Orders].OrderID ,
> [Order Details].Discount,
> [Customers].CustomerID ,
> [Shippers].ShipperID ,
> [Shippers].CompanyName
> from
> [Orders] inner join [Order Details] on [Orders].OrderID = [Order
>Details].OrderID
> inner join [Customers] on [Orders].CustomerID = [Customers].CustomerID
> inner join [Shippers] on [Orders].ShipVia = [Shippers].ShipperID
>
>I use Northwind as the test database, here Order Details is Table1, Orders
>is Table2, Customers is Table3, Shippers is Table4


Yes that is what we do. I think what you did above is the answer I am
looking for:

[Customers] on [Orders].CustomerID = [Customers].CustomerID inner join
[Shippers] on [Orders].ShipVia = [Shippers].ShipperID

You join Customers to Shippers but the connection is Orders
(previously listed) to Shippers. That is what I was not thinking of.

Thank you - great job!!!


david@at-at-(E-Mail Removed)
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Joining Tables Ktowner Microsoft Access Database Table Design 2 19th Aug 2009 06:44 PM
Joining Tables Idaho Word Man Microsoft Word Document Management 7 9th Jul 2008 11:15 PM
Joining tables =?Utf-8?B?U2ls?= Microsoft Access 1 12th Jan 2006 12:48 PM
Joining Tables =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft Dot NET 0 6th Jul 2005 07:56 PM
Joining Tables Rob Edwards Microsoft ADO .NET 3 6th Aug 2003 08:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:40 PM.