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)
 finding possible table relationships

Author  Topic 

nmonte
Starting Member

2 Posts

Posted - 2001-07-27 : 09:10:30
I'm wondering if anyone knows of a code snippet, or tool out there that would do the following.. It's basically a query builder..

-- accept 1 or more tables as input
-- examine the table(s) for possible joins
(by finding matching field names in each table)
-- return 1 or more sql strings for each possible join type

For example here are 3 tables example..

TASKS
========
taskid
projectid
statusid
task

PROJECTS
==========
projectid
project

STATUS
=========
statusid
status

I'd want to have it return the following sql strings...

select * from tasks,projects,status where projects.projectid = tasks.projectid and status.statusid = tasks.statusid

select * from tasks left join status on status.statusid = tasks.statusid, projects where projects.projectid = tasks.projectid

select * from tasks right join status on status.statusid = tasks.statusid, projects where projects.projectid = tasks.projectid

select * from tasks left join projects on projects.projectid = tasks.projectid, status where status.statusid = tasks.statusid

select * from tasks right join projects on projects.projectid = tasks.projectid, status where status.statusid = tasks.statusid

select * from tasks left join projects on projects.projectid = tasks.projectid left join status on status.statusid = tasks.statusid

select * from tasks right join projects on projects.projectid = tasks.projectid right join status on status.statusid = tasks.statusid

etc...

I could probably write it, but I thought it might already exist somewhere.

Thanks.
Nathan


   

- Advertisement -