I have a "StoreNumber" column in my "Project" table that I want to change to "NOT NULL". I recently cleared all the old data so that there are no null entries. However, when I execute the following statement, it fails due to several dependencies on different views, indexes, and statistics
ALTER TABLE [Project] ALTER COLUMN StoreNumber VARCHAR(9) NOT NULL GO
What is the fastest way to delete all of these views / indexes / statistics, then run the alter statement and then re-create all the views / indexes / statistics? I know that I could copy all the drop and create statements one by one, but I would prefer to generate the script in one request.
On the other hand, why does SQL Server care if I make the column more restrictive? The data does not contain zeros, and I do not change the data type or the size of the columns. How would this type of change ever violate a dependent view, index, or statistics? I am sure that there are sound arguments that I do not see, but I would like to give an example.
source share