I have this huge data base (1669 Tables) that I am trying to 'analyze' and one of the 'checks' is: how many PK-FK Relations do I have between the tables?
From this site I've got some good SQL's to list tables with FK and related tables with PK. I have (only) 157 records. Great!
Something like:[tt]
SELECT OBJECT_NAME(fkeys.constraint_object_id) foreign_key_name
,OBJECT_NAME(fkeys.parent_object_id) referencing_table_name
,COL_NAME(fkeys.parent_object_id, fkeys.parent_column_id) referencing_column_name
,OBJECT_NAME (fkeys.referenced_object_id) referenced_table_name
,COL_NAME(fkeys.referenced_object_id, fkeys.referenced_column_id)
referenced_column_name
FROM sys.foreign_key_columns AS fkeys
order by 2[/tt]
So, I stared to drag 2 tables at the time to [blue][tt]Views - New view...[/tt][/blue] in MS Management Studio just to verify the PK-FK relations, easy to see the 'automagic' connection between tables this way. Some of them showed 'connection' between the tables just like I expected. But there are some pairs that even though are listed with PK-FK relation, they are not 'connected' at all. :-(
Creating ER Diagram is out of the question - too many tables, Management Studio crashes.
How can I get the list of tables that do have actual PK-FK relation established?
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
From this site I've got some good SQL's to list tables with FK and related tables with PK. I have (only) 157 records. Great!
Something like:[tt]
SELECT OBJECT_NAME(fkeys.constraint_object_id) foreign_key_name
,OBJECT_NAME(fkeys.parent_object_id) referencing_table_name
,COL_NAME(fkeys.parent_object_id, fkeys.parent_column_id) referencing_column_name
,OBJECT_NAME (fkeys.referenced_object_id) referenced_table_name
,COL_NAME(fkeys.referenced_object_id, fkeys.referenced_column_id)
referenced_column_name
FROM sys.foreign_key_columns AS fkeys
order by 2[/tt]
So, I stared to drag 2 tables at the time to [blue][tt]Views - New view...[/tt][/blue] in MS Management Studio just to verify the PK-FK relations, easy to see the 'automagic' connection between tables this way. Some of them showed 'connection' between the tables just like I expected. But there are some pairs that even though are listed with PK-FK relation, they are not 'connected' at all. :-(
Creating ER Diagram is out of the question - too many tables, Management Studio crashes.
How can I get the list of tables that do have actual PK-FK relation established?
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson