开发者

SQL Server update query that only update table itself not indexes

I need to write a query that update only table not indexes because I want to update an int 开发者_如何学Cfield and don't need to 10 huge index to be updated


If the int field is included in any of the index definitions then they will have to be updated too.

SQL Server won't allow the base table to have one value and the indexes another for obvious data integrity reasons.

If the int field is not included in any of the index definitions then only the table will be updated anyway.

You can disable the indexes but to re-enable them involves rebuilding the whole index.


It depends on what you really want to do

Keeping the index consistent with the table data is the Consistency in ACID. This is how SQL Server and ACID-compliant RDBMSes work.

There are cases such as bulk loads where you want to delay this Consistency. So if you have this use case, DROP or DISABLE the indexes.

If you disable the indexes:

  • they will never be used for any query-
  • all associated unique and foreign keys etc will be disabled too
  • they are not maintained

If you DROP them, of course they can't be used either.

After your bulk load is finished, you enable or create the indexes/constraints again.

If this is what you really want then read MSDN:

  • Disabling Indexes
  • Guidelines for Disabling Indexes and Constraints


Perhaps Filtered Indexes are what you're looking for.

This is a SQL Server 2008 feature that lets you create an index that only applies to certain values in a column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜