Tuesday, March 20, 2012

Primary Key Analysis Tool

I have a client database where the users are experiencing very unpredictable behavior and I found after investigating that the majority of the tables don't have primary keys. :o

They were imported from an Access database and I think the table creator or the Access wizard itself added auto-number fields, so I know most of the tables have at least one column that could become the primary key.

Is there a free tool available that will allow me to analyze these tables to identify and list the tables that need primary keys and also help identify candidate columns for the primary key?

It would be helpful if I could automate some of the script generation to install the primary keys so I don't have to do them all manually.you should be able to work out a query using the information schema views.|||Is it a full moon toay?

Script out the database and look it over

Or do as Sean said and left join tables key_column_usage|||Is it a full moon toay?

Script out the database and look it over

Or do as Sean said and left join tables key_column_usage
No, sorry the moon was full on the 26th.

The reason I asked about a tool to help with this is I don't have time or patience to script and analyze about 500 tables. The key_column_usage view isn't helpful since none of the user tables have keys - there are only two entries for the master table keys.|||This script is beta, but it works pretty well. Supply a tablename and it will find all the natural keys in the data.|||I didn't open the blind dudes script, but I guess it's looking for cardiality of the data.

The more unique it is would be the key

But you could write your own

So lets' you find a column that all has unique values, I would use that as a key

But what if you have columns with 2 or 3 values?

Or mostly unique?

Was that app written to suppose to enforce RI

A lot of 3rd party apps I see do that

scrubs|||This script is beta, but it works pretty well. Supply a tablename and it will find all the natural keys in the data.
Exactly what I needed. :beer:

No comments:

Post a Comment