I am trying to code a tsql routine to check for the existence of statistics before a column is dropped. If the stats exist I want to drop the stats first and then drop the column. I Can do this manually but need it in a script.
First reason is that the column cannont be dropped while the statistic is pressent.
Second, there are 15 db's that need to have the obsolete column(s) dropped.
Third, all steps are documented.
Fourth, gui's take 2 long. Just run a command.
Fifth, There are dozens of obsoleted columns that are being dropped in the next release.
eg.sample of the errors generated.
Server: Msg 5074, Level 16, State 8, Line 9
The statistics 'HHAltCouponName' is dependent on column 'HHAltCouponName'.
Server: Msg 4922, Level 16, State 1, Line 9
ALTER TABLE DROP COLUMN HHAltCouponName failed because one or more objects access this column.