Solved

Error "It contains one or more disallowed constructs" On SQL View and Clustered Index

Posted on 2004-09-29
7
2,339 Views
Last Modified: 2013-11-15
Hi,

I am trying to create a clustered index on a view I am creating but it keep s retruening with

It contains one or more disallowed constructs

I have tried this with out a left outer join and it works. Yet when I add the left outer join on the end it doesn't work? I have seen in other areas on the net where people have managed to use a left outer join in the creation of view, yet I am still at a loss to whether I am doing anything wrong in the statement, or  whether Left outer joins are a no go? Is it Possible? Here is the query etc i am using to create the View...any idea?

CREATE VIEW 1EMAIL

WITh SCHEMABINDING

AS


select '1' as sortby,contact1.accountno,contact1.company,contact1.title,contact1.contact,
contact1.phone1 as direct,contact1.phone2 as switch,contact1.phone3 as Mobile,contact1.fax,contact1.ext3,contact1.key1,
contact1.key2,contact1.key3,contact1.key4,contact1.key5,contact1.mergecodes,conts.contsupref as email
from dbo.contact1  LEFT OUTER JOIN
                          (SELECT     accountno, contsupref
                            FROM          dbo.contsupp
                            WHERE      zip LIKE '_1%' AND contsupp.contact LIKE 'E-mail%') as conts ON dbo.CONTACT1.ACCOUNTNO = conts.accountno


GO

CREATE UNIQUE CLUSTERED INDEX indClustered

ON GM.DBO.1EMAIL (accountno)

GO
0
Comment
Question by:Squeel
7 Comments
 
LVL 26

Expert Comment

by:Hilaire
ID: 12177647
Try whithout the sub-select as follows

CREATE VIEW 1EMAIL
WITh SCHEMABINDING
AS
select '1' as sortby,contact1.accountno,contact1.company,contact1.title,contact1.contact,
contact1.phone1 as direct,contact1.phone2 as switch,contact1.phone3 as Mobile,contact1.fax,contact1.ext3,contact1.key1,
contact1.key2,contact1.key3,contact1.key4,contact1.key5,contact1.mergecodes,conts.contsupref as email
from dbo.contact1
LEFT OUTER JOIN dbo.contsupp conts
ON dbo.CONTACT1.ACCOUNTNO = conts.accountno AND zip LIKE '_1%' AND contsupp.contact LIKE 'E-mail%'

0
 

Author Comment

by:Squeel
ID: 12177874
Thanks, ok have tried what you have suggested but no joy I am afraid.


CREATE VIEW 1EMAIL
WITh SCHEMABINDING
AS
select '1' as sortby,contact1.accountno,contact1.company,contact1.title,contact1.contact,
contact1.phone1 as direct,contact1.phone2 as switch,contact1.phone3 as Mobile,contact1.fax,contact1.ext3,contact1.key1,
contact1.key2,contact1.key3,contact1.key4,contact1.key5,contact1.mergecodes,conts.contsupref as email
from dbo.contact1
LEFT OUTER JOIN dbo.contsupp conts
ON dbo.CONTACT1.ACCOUNTNO = conts.accountno AND conts.zip LIKE '_1%' AND conts.contact LIKE 'E-mail%'

GO

CREATE UNIQUE CLUSTERED INDEX indClustered

ON GM.DBO.1EMAIL (accountno)

GO


--------------It is still coming back with ---------

Server: Msg 1936, Level 16, State 1, Line 1
Cannot index the view 'GM.dbo.EMAIL100'. It contains one or more disallowed constructs.

I can get the view created with SCHEMABINDING applied but  It seems the indexing part is kicking up a fuss
0
 
LVL 12

Expert Comment

by:patrikt
ID: 12177968
From InsideSQL:
-----------------
In addition to the requirement that all functions used in the view be deterministic and that the seven SET options be set to the appropriate values, the view definition can't contain any of the following:

TOP
text, ntext, or image columns
DISTINCT
MIN, MAX, COUNT(*), COUNT(<expression>), STDEV, VARIANCE, AVG
SUM on a nullable expression
A derived table
The ROWSET function
Another view (you can reference only base tables)
UNION
Subqueries, OUTER joins, or self-joins
Full-text predicates (CONTAINS, FREETEXT)
COMPUTE, COMPUTE BY
ORDER BY
-------

On first sight I could not decide if any of disalloowed constructs are used. But may be you can.
Try to go through this list, may be it helps.

Patrik

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 12

Expert Comment

by:patrikt
ID: 12177982
Oops.
I owerlooked that Outer Join is disallowed. There is a problem.

Probably there is way with Inned join.

Patrik
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 12178527
Could it be  the refence to the unaliased table name in:
>contsupp.contact LIKE 'E-mail%'

That should perhaps be
cont.contact LIKE 'E-mail%'

0
 

Author Comment

by:Squeel
ID: 12179146
Thanks Patrik I will try the inner join but dont think this will work.

In both cases the actual Views themselves work and also work as standard SQL expressions.

Thanks monosodiumg but already tried that in the second version of the View query?


Any other ideas?

Along way round but may have to create an indexed view for each part of the query then create a final view to draw the two seperate views together? Dont know if possible though?
0
 
LVL 12

Accepted Solution

by:
patrikt earned 125 total points
ID: 12179396
Your last suggestion is probably faster solution.

Outer joins are not indexable becouse of possible nulls on one side. It leads sqlserver to nondeterministic solution which is not indexable.
If you separate both parts you will add two indexes and sql will chose which one (or both) to use.

Patrik
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now