Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Wired problem with index on view - error 1947

$
0
0

Hello all,

In AdventureWorks database (SQL 2008, 2012 - no difference) I have a view defined as follows:

create view [dbo].[SalesOrderAddressView]
with schemabinding as
select soh.SalesOrderID, a1.AddressLine1 BillToAddress, a2.AddressLine1 ShippToAddress
from Sales.SalesOrderHeader soh
inner join Person.Address a1 on soh.BillToAddressID = a1.AddressID
inner join Person.Address a2 on soh.ShipToAddressID = a2.AddressID


Now, I try to create an index as follows:

CREATE UNIQUE CLUSTERED INDEX [SalesOrderAddressIndex] ON [dbo].[SalesOrderAddressView] ([SalesOrderID] ASC)

SQL Server 2012 says:

Msg 1947, Level 16, State 1, Line 1

Cannot create index on view "AdventureWorks.dbo.SalesOrderAddressView". The view contains a self join on "AdventureWorks.Person.Address".


What is the problem? Why it thinks the view contains a self join while it does not? Is it due to the way the query actually gets executed? How to create an index on such view containing more than one join to the same table?

I will appreciate any hints.


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>