I agreeto Idea Statistics Drop Needs Check

2 votes

Rank42

Idea#15

This idea is in progress.
Schema Compare »

Statistics Drop Needs Check

When generating the output script for a schema compare, the drop for statistics is not being wrapped in a check to make sure the statistic exists.

For example:

USE AdventureWorks2008R2;

GO

IF EXISTS (SELECT name FROM sys.stats

WHERE name = N'ContactPromotion1'

AND object_id = OBJECT_ID(N'Person.Person'))

DROP STATISTICS Person.Person.ContactPromotion1

GO

Comment

Submitted by Rick Mathers 1 year ago

Events

  1. Status Changed from Active to In Progress
    5 months ago
  2. The idea was posted
    1 year ago

Comments (2)

  1. Do you need this check only for statistics? Only for drop? Do you need drop..exists before create statistics?

    Or for any other objects(triggers, columns and etc.)

    1 year ago
    1. Currently, when generating a script from Schema compare the drops are handled at the front of the script and the creates are done towards the end. So the drop..exists before the create would not make sense, at least for the Schema Compare.

      For the other objects, I would love to see guards around all of the drop statements, the main problem with statistics is that SQL can generate them on the fly where as the other objects are going to be created by a developer.

      Looking through a script that was generated by Schema compare the following should have guards around them before executing a drop:

      Statistics

      Indexes

      Tables

      Constraints

      Views

      1 year ago