brundlefly
brundlefly

Reputation: 31

Creating Index on Table in a schema

I am logged in as 'sa', with full admin rights, and I am running the following command:

CREATE NONCLUSTERED INDEX [IDX_EntityAuditId] ON [Maintenance.EntityAuditMessagesArchive] 
([EntityAuditId] ASC) ON [PRIMARY]

and getting the error:

Cannot find the object "Maintenance.EntityAuditMessagesArchive" because it does not exist or you do not have permissions.

The object does exist, because I can select from it. Furthermore, the command works if the table is not in a schema. i.e.

CREATE NONCLUSTERED INDEX [IDX_EntityAuditId] ON [EntityAuditMessagesArchive] 
    ([EntityAuditId] ASC) ON [PRIMARY]

works (when I create the table without a schema, of course).

So, I can't create the index when the table is in the Maintenance schema. Why is this?

Upvotes: 1

Views: 3560

Answers (1)

JNK
JNK

Reputation: 65157

You have a . in your name. I'm guessing you need to change it to:

[Maintenance].[EntityAuditMessagesArchive]

A period inside the brackets indicates it is a part of the name, not a separator.

Upvotes: 3

Related Questions