SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Search for relationship


Search for relationship

Author
Message
sdhamani1020
sdhamani1020
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 36
I have a table having company names and another table having Revenueid and amount of Revenue but dont seem t get the relationship where it says which company pays what amount oof revenue.

How can I see that. No common columns in these two tables.
There are lot of other tables in the DB but I dont seem to find one which can show the relationship and get me the data.

Pls suugest.
Luis Cazares
Luis Cazares
SSC-Forever
SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)SSC-Forever (42K reputation)

Group: General Forum Members
Points: 42854 Visits: 19847
Could you post DDL for both tables? Some comments on what the columns are could be useful.

Additionaly, you could use the system views to find any Primary keys or Foreign keys on both tables.

SELECT *
FROM sys.objects
WHERE type IN ('F', 'PK')
AND parent_object_id IN( OBJECT_ID( 'Saldos_Emp', 'U'), OBJECT_ID( 'AnotherTable', 'U'))




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Dave62
Dave62
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3580 Visits: 2835
This will be pretty hard to answer definitively without having a lot more information about all the tables and fields in the database.

Totally grasping at straws, I'm wondering if the table that has the company names also has a CompanyId field and if so then maybe the CompanyId field is related the RevenueId field in the other table.

One possible way to see relationships is to add the table with the company names to a new database diagram in SSMS and then right-click in the new diagram window and pick "Add Table..." to add the table with the company names to the diagram. Once the table comes up in the new diagram window you can right-click the table and pick "Add Related Tables". That option will be greyed-out (disabled) if the table has no related tables. If the option is enabled and you click it, all the related tables will be added to the diagram. You can then check the properties of each relationship to see what columns in the other tables are related to what columns in the table with the company names.
sdhamani1020
sdhamani1020
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 36
I tried this option. Apparently the table with CompanyID does not have any related table.
However , the table with revenue id , does bring up lot of related ones....
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64185 Visits: 17974
sdhamani1020 (6/13/2013)
I tried this option. Apparently the table with CompanyID does not have any related table.
However , the table with revenue id , does bring up lot of related ones....


Well since we can't see your screen we can't really do much to offer as help here. There must be something somewhere that ties these tables together. Maybe you have to go through another table or two to get there?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Dave62
Dave62
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3580 Visits: 2835
sdhamani1020 (6/13/2013)
I tried this option. Apparently the table with CompanyID does not have any related table.
However , the table with revenue id , does bring up lot of related ones....


Sometimes the developer who setup the original design was "nice" enough to put fields that are related in tables but without actually creating foreign keys. So it's possible that CompanyID is related to revenue id without a foreign key existing. Or CompanyID may be related (without a foreign key) to a field in one of the other tables that is connected to revenue id.

If you find that to be the case, you may want to consider putting the foreign key(s) in place to make your life and the next guys easier going forward. ;-)
Sean Pearce
Sean Pearce
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4172 Visits: 3436
Do you have any database documentation?



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
OTF
OTF
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1282 Visits: 4128
This is a difficult one to answer without access to your database or a lot more info. on it.
Maybe a database/entity relationship diagram.
Tables can be "related" without "hard coded" Foreign Key Relationships in place at which point it pretty much comes down to a bit of investigation on your part to detect the relationships.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search