今天准备在SQL Server2005的一个表的字段上间索引,结果创建失败。检查一下表结构,原来该字段是NVarchar(Max), 不能建索引。
后来将该字段改成nvarchar(4000),重新执行创建语句,出现如下提示:
Warning! The maximum key length is 900 bytes. The index 'IX_PROJECT_LABEL' has maximum length of 8000 bytes. For some combination of large values, the insert/update operation will fail.
查询MSDN,
解释如下:
When you design an index that contains many key columns, or large-size columns, calculate the size of the index key to make sure that you do not exceed the maximum index key size. SQL Server retains the 900-byte limit for the maximum total size of all index key columns. This excludes nonkey columns that are included in the definition of nonclustered indexes.
To calculate the size of an index key, follow these steps.
- Display the properties of the table columns on which the index will be based. You can do this by using the sys.columns catalog view.
- Sum the length of each column that will be defined in the index key.
For example, the following statement aggregates themax
_length
column of thesys.columns
catalog view for the spe