Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By William Talada,
ShowColumnUsage presents table columns in a format for you to see all constraints, indexes, and foreign keys affecting each column. You'll be shocked at how many errors you'll find in your constraints and indexes within seconds of running it. I never deploy to customers without running this first.
I'll walk you through it quickly. Create the proc in msdb and do the following to see the results for all tables:
exec ShowColumnUsage '%'
Notice that all constraints and indexes numbered 1 are clustered.
Now let's see all the botched indexes in msdb...
-- non-unique clustered index is in reverse order from the foreign key definition-- seems illogical but maybe they have their reasonsexec ShowColumnUsage 'DTA_reports_querytable'
-- idx2 is a complete waste since pk1.1 has it covered-- only makes sense in a few critical situationsexec ShowColumnUsage 'log_shipping_primary_secondaries'
-- ak2 and udx3 are equal so one is redundantexec ShowColumnUsage 'log_shipping_primary_databases'
-- this one is just plain weird having an alternate key that is part of a primary key???exec ShowColumnUsage 'sysdtspackages'
Now run it in your databases and fix errors you could never see before.
Violation of PRIMARY KEY constraint
Primary keys and indexes
Violating the primary key constraint
Can't Delete Index b/c of Constraint
Primary Key, Clustered Index, Modification