我正在尝试在以下视图上创建索引:
SELECT 'Candidate' AS Source,CandidateID AS SourceId,LastName + ',' + FirstName AS SourceName FROM dbo.Candidates UNION SELECT 'Resource' AS Source,ResourceID AS SourceId,' + FirstName AS SourceName FROM dbo.Resources UNION SELECT 'Deal' AS Source,DealID AS SourceId,CONVERT(varchar,Number) + '-' + CONVERT(varchar,RevisionNumber) AS SourceName FROM dbo.Deals UNION SELECT 'Job Order' AS Source,JobOrderID AS SourceId,CustomerNumber AS SourceName FROM dbo.JobOrders
我收到以下错误:
Msg 1939,Level 16,State 1,Line 2 Cannot create index on view '_Source' because the view is not schema bound.
我将WITH SCHEMABINDING添加到CREATE,现在出现以下错误:
Msg 10116,Line 2 Cannot create index on view 'DEALMAKER.dbo._Source' because it contains one or more UNION,INTERSECT,or EXCEPT operators. Consider creating a separate indexed view for each query that is an input to the UNION,or EXCEPT operators of the original view.
我的问题是:
如何在此视图上创建索引?创建单独的索引视图真的有效吗?
提前致谢!