Вопрос по sql-server, sql – Что такое неточный столбец в SQL Server?
Создание индекса по вычисляемому столбцу типаnvarchar
возникает следующая ошибка:
Cannot create index or statistics 'MyIndex' on table 'MyTable' because the computed column 'MyColumn' is imprecise and not persisted. Consider removing column from index or statistics key or marking computed column persisted.
Что значитimprecise колонка значит?
ОБНОВИТЬ. Определение следующее:
<code>alter table dbo.MyTable add [MyColumn] as dbo.MyDeterministicClrFunction(MyOtherColumn) go create index MyIndex on dbo.MyTable(MyColumn) go </code>
UPDATE2.MyDeterministicClrFunction
определяется следующим образом:
<code>[SqlFunction(IsDeterministic = true)] public static SqlString MyDeterministicClrFunction(SqlString input) { return input; } </code>
PERSISTED
на вашALTER TABLE
заявление
MyOtherColumn
другой столбецnvarchar(50)
.
nvarchar(xx)
или жеnvarchar(max)
?
Для MSDN столбцы функций CLR должны быть сохранены для индексации:
Any computed column that contains a common language runtime (CLR) expression must be deterministic and marked PERSISTED before the column can be indexed. CLR user-defined type expressions are allowed in computed column definitions. Computed columns whose type is a CLR user-defined type can be indexed as long as the type is comparable. For more information, see CLR User-Defined Types.
Сохраняйте колонку, и я подозреваю, что она будет работать.
Any float or real expression is considered imprecise and cannot be a key of an index; a float or real expression can be used in an indexed view but not as a key. This is true also for computed columns. Any function, expression, or user-defined function is considered imprecise if it contains any float or real expressions. This includes logical ones (comparisons).
nvarchar
.
Ты пытался:
[SqlFunction(IsDeterministic=true, IsPrecise=true)]
http://msdn.microsoft.com/en-us/library/orm-9780596101404-02-12.aspx
http://msdn.microsoft.com/en-us/library/ms189292.aspx
Похоже, что сообщение об ошибке вводит в заблуждение, потому что вычисленные столбцы CLR должны быть сохранены в любом случае (для индексации).
Cannot create index or statistics 'MyIndex' on table 'MyTable' because SQL Server cannot verify that key column 'MyColumn' is precise and deterministic. Consider removing column from index or statistics key, marking computed column persisted, or using non-CLR-derived column in key.