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!
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.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句