Sekhar
Sekhar

Reputation: 5787

Find foreign keys based on data

I am looking at a database which has almost no foreign keys defined.

Is there a tool that can perform some data analysis/heuristics and "guess" the relations based on data. I am looking for some kind of report, which can be used as a manual guide/checklist.

Upvotes: 0

Views: 25

Answers (1)

john McTighe
john McTighe

Reputation: 1181

I had a similar problem - Every Table had a Object_ID column... But had secondary IDs too. All were of a wierd GUID-ish form. I ended up writing a brute force scanner (using Dynamic sql from informtion_schema.columns)

Of course this approach relied on the values being globally unique... If you have a bunch of int identity cols and no way to connect the Tables then you are in a bit of trouble!

Perhaps there is a timestamp column or a DateTime defaulting to GetDate() - you could use this to identidy records in different tables that are created at approx the same time.

A lot depends on your schema...

Upvotes: 1

Related Questions