Quickly dropping and re-creating multiple indexes, views, statistics when altering a column

萝らか妹 提交于 2019-12-05 18:20:43

Just thinking; will it work if you set a default value first? (dind't check the sintax myself)

ALTER TABLE Project
ADD CONSTRAINT col_sn_def
DEFAULT '' FOR StoreNumber;
GO

The following will drop multiple indexes. Note that the final statement does not include the comma.

DROP INDEX [index1_1] ON [schema].[table1],
           [index1_2] ON [schema].[table1],
           [index2_1] ON [schema].[table2],
           [index3_1] ON [schema].[table3],
           ...n,
           [lastIndexToDrop] ON [schema].[tableName]

Drop View looks like this. Note the semicolon to terminate the statement.

DROP VIEW [schema].[view1], [schema].[view2];

I am only concerned with Indexes in my application at this time. To quickly recreate the indexes, I am reading a .sql file into code and executing it in an ExecuteNonQuery call. If I had views to consider, I would follow the same method of reading from a file into a command to execute with ExecuteNonQuery.

https://msdn.microsoft.com/en-us/library/ms173492.aspx

https://msdn.microsoft.com/en-us/library/ms176118.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!