2012-05-07 20 views
8

प्रकार nvarchar की गणना की स्तंभ पर सूचकांक बनाना निम्नलिखित उठाती त्रुटि:SQL सर्वर में अपरिचित कॉलम क्या है?

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.

क्या अनिश्चित स्तंभ मतलब है?

अद्यतन। परिभाषा निम्न है:

alter table dbo.MyTable 
    add [MyColumn] as dbo.MyDeterministicClrFunction(MyOtherColumn) 
go 
create index MyIndex on dbo.MyTable(MyColumn) 
go 

UPDATE2। MyDeterministicClrFunction निम्नलिखित के रूप में परिभाषित किया गया है:

[SqlFunction(IsDeterministic = true)] 
public static SqlString MyDeterministicClrFunction(SqlString input) 
{ 
    return input; 
} 
+0

आप गणना कॉलम मान के लिए किस सूत्र का उपयोग करने का प्रयास कर रहे हैं? – Yuck

+0

क्या यह 'nvarchar (xx) 'या' nvarchar (अधिकतम) 'है? – JNK

+0

'मायऑथर कॉलम' अन्य कॉलम 'nvarchar (50) 'है। –

उत्तर

9

Per MSDN, CLR Function columns must be persisted to be indexed:

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.

स्तंभ बनी रहती है और मैं इसे काम करेंगे संदेह है।

+0

तो संदेश गलत है , यह कह रहा है कि यह अपरिहार्य है? –

+0

@ टीएन। मुझे लगता है कि त्रुटि संदेश शायद इस मामले के लिए विशिष्ट नहीं है, लेकिन इस त्रुटि से जुड़ा एक और सामान्य संदेश है। – JNK

+0

ठीक है, मैं देखता हूं ... :) –

6
SQL server documentation से

:

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).

+2

जैसा कि आप मेरे कॉलम को पढ़ सकते हैं, 'nvarchar' टाइप करें। –

+0

@ टीएन - ऐसा इसलिए हो सकता है क्योंकि यह परिणामी वर्चर के आकार को निर्दिष्ट नहीं करता है? –

+0

या ऐसा इसलिए हो सकता है क्योंकि यह – JNK

1

आप की कोशिश की है: त्रुटि संदेश की तरह है क्योंकि CLR अभिकलन कॉलम वैसे भी कायम किया जाना है (अनुक्रमित करने के लिए) भ्रामक है

[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

लग रहा है।

+0

+1 Thx, लेकिन यह थोड़ा बेहतर त्रुटि संदेश देता है: 'तालिका' MyTable 'पर इंडेक्स या आंकड़े' MyIndex 'नहीं बना सकता क्योंकि SQL सर्वर सत्यापित नहीं कर सकता कि कुंजी कॉलम' MyColumn 'सटीक है और निर्धारक। इंडेक्स या आंकड़े कुंजी से कॉलम को हटाने, गणना किए गए कॉलम को चिह्नित करने, या कुंजी में गैर-सीएलआर-व्युत्पन्न कॉलम का उपयोग करने पर विचार करें। –

संबंधित मुद्दे