SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Index cannot be created on view because the underlying object has a different owner


Index cannot be created on view because the underlying object has a different owner

Author
Message
vikas.chaudhary
vikas.chaudhary
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 155
Hello Guys,

We are getting the below error while creating the clustered index on the index view:

"Index cannot be created on view because the underlying object has a different owner"

The schemas of the "base table" referred in the view and actual schema of the "view" are owned by different database roles and that's why we are getting this error.

As a work-around, I am thinking of making "dbo" user as the owner of both the schemas (base table and indexed view schema) and then grant full permission to database roles of "base table" and "indexed view" on their respective schemas

Question: Does this approach has any security concerns when all the schemas will be owned by dbo user ?

Thanks in advance,

Vikas
Dennis Post
Dennis Post
SSC-Addicted
SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)

Group: General Forum Members
Points: 407 Visits: 547
Set it up in development.
Make the changes.
Try your best to take advantage of the new rights.



For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Dennis Post
Dennis Post
SSC-Addicted
SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)

Group: General Forum Members
Points: 407 Visits: 547
Here's a script to reproduce the error and correct it.

CREATE SCHEMA Test1 AUTHORIZATION Guest
GO
CREATE SCHEMA Test2 AUTHORIZATION dbo
GO

IF OBJECT_ID('Test1.Tmp1') IS NOT NULL
DROP TABLE Test1.Tmp1

CREATE TABLE Test1.Tmp1
(
ID INT IDENTITY,
CharVal Char(1),
)

IF OBJECT_ID('Test1.Tmp2') IS NOT NULL
DROP TABLE Test2.Tmp2

CREATE TABLE Test2.Tmp2
(
ID2 INT IDENTITY,
CharVal2 Char(1)
)

INSERT Test1.Tmp1
SELECT TOP 100 CHAR(ABS(CHECKSUM(NEWID()) % 26) +97)
FROM sys.all_columns c1, sys.all_columns c2

INSERT Test2.Tmp2
SELECT TOP 100 CHAR(ABS(CHECKSUM(NEWID()) % 26) +97)
FROM sys.all_columns c1, sys.all_columns c2
GO
-- DROP VIEW Test1.View1
CREATE VIEW Test1.View1
WITH SCHEMABINDING
AS
(
SELECT T1.ID, T1.CharVal, T2.CharVal2
FROM Test1.Tmp1 T1
JOIN Test2.Tmp2 T2
ON T1.ID = T2.ID2
)
GO

CREATE UNIQUE CLUSTERED INDEX UCI_TmpTest ON Test1.View1 (ID, CharVal, CharVal2)
--Generates error
--Msg 1938, Level 16, State 1, Line 1
--Index cannot be created on view 'View1' because the underlying object 'Tmp2' has a different owner.
GO
ALTER AUTHORIZATION ON SCHEMA::Test1 TO dbo
GO
-- Try creating the unique clustered index again
CREATE UNIQUE CLUSTERED INDEX UCI_TmpTest ON Test1.View1 (ID, CharVal, CharVal2)
GO

DROP VIEW Test1.View1
DROP TABLE Test1.Tmp1
DROP TABLE Test2.Tmp2

DROP SCHEMA Test1
DROP SCHEMA Test2



Make sure you make a reversing script just in case.



For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2205 Visits: 872
It is difficult to answer the question, because I don't know why you set up different schema owners in the first place. My preference is to have dbo to own everything, but that also requires the right way of thinking about security for that model.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search