Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Search for relationship Expand / Collapse
Author
Message
Posted Thursday, June 13, 2013 1:05 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 5, 2013 11:35 AM
Points: 11, 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.
Post #1463271
Posted Thursday, June 13, 2013 1:27 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:38 PM
Points: 3,939, Visits: 8,935
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1463281
Posted Thursday, June 13, 2013 1:36 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:42 AM
Points: 2,150, Visits: 2,152
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.
Post #1463284
Posted Thursday, June 13, 2013 2:06 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 5, 2013 11:35 AM
Points: 11, 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....
Post #1463298
Posted Thursday, June 13, 2013 2:34 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:10 AM
Points: 13,230, Visits: 12,709
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 Moden's 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)
Post #1463309
Posted Friday, June 14, 2013 6:53 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:42 AM
Points: 2,150, Visits: 2,152
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.
Post #1463534
Posted Friday, June 14, 2013 7:24 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 11:35 AM
Points: 975, Visits: 3,037
Do you have any database documentation?




The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Post #1463560
Posted Monday, June 17, 2013 3:40 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
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.
Post #1464044
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse