There is a very old product, that has more than 1500 tables and there is no foreign key relationship defined between tables.
Is there any way so we can find out the relationship of tables?
Thanks!
There is a very old product, that has more than 1500 tables and there is no foreign key relationship defined between tables.
Is there any way so we can find out the relationship of tables?
Thanks!
Without any FK's, it's impossible to determine, exactly, what, if any, relationships tables have. You might be able to determine this in an application that calls the DB. For example, if an application uses Entity Framework or Linq to SQL and uses the DB, the relationships could be defined in the model, even thought they aren't defined in the DB. Even without this, it might be possible to determine relatioships by examining how data is rerieved and classes created from this data.
If there's no relationships between tables then there's no relationships between tables. Anything that could be done would be somewhat guesswork and the results will be mediocre at best, and that would all depend on how the original developers named the tables and columns.
Something that could potentially get you started would be the following query:
select distinct t1.name
from sys.columns s1
inner join sys.tables t1 on t1.object_id = s1.object_id
inner join sys.columns s2 on s1.name = s2.name
and s1.object_id <> s2.object_id
inner join sys.tables t2 on t2.object_id = s2.object_id
this will get you a list of tables that have a column with an exact match with another table. Note there will be a lot of noise returned from this query (most likely) but it might be a help to get you started.