Script – Columns Without Foreign Keys

I ran across some instances in a legacy database where some numeric codes where being stored with no reference table for these values. Luckily, the values were enumerated in the application code. Obviously it is preferable to have these values in the database where a foreign key can restrict the values stored in the referencing column, as well as give a way to interpret the values.
I created a script to search for columns in a database that don’t have a foreign key referencing them. I include a parameter to limit the search to numeric values. Other than a generated primary key value, we would imagine that most numeric values are referring to another value.

The script is available on GitHub.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: