Question

I am trying to alter my table schema from MySchema.TableName to dbo.TableName using the following command -

ALTER SCHEMA MySchema TRANSFER dbo.TableName

I get the following error -

Msg 15151, Level 16, State 1, Line 1
Cannot find the object 'TableName', because it does not exist or you do not have permission.

By searching I also added the following commands to no avail.

ALTER AUTHORIZATION ON SCHEMA::MySchema to dbo;
ALTER AUTHORIZATION ON OBJECT::MySchema.TableName TO SCHEMA OWNER;
ALTER SCHEMA MySchema TRANSFER dbo.TableName

I keep getting the same error.

My table name is correct and so is the database where I am running. Any help?

Was it helpful?

Solution

You have the schemas backwards.

Change...

ALTER SCHEMA MySchema TRANSFER dbo.TableName

...to:

ALTER SCHEMA dbo TRANSFER MySchema.TableName

See a related SO answer for confirmation where the source and target schemas should be in your ALTER SCHEMA statement.

If the ALTER SCHEMA statement still does not work, then you have another issue (e.g. you don't have necessary permissions).

For any permissions issues you may bump into, refer to TechNet's ALTER SCHEMA reference, specifically its Permissions section, which says:

To transfer a securable from another schema, the current user must have CONTROL permission on the securable (not schema) and ALTER permission on the target schema.

If the securable has an EXECUTE AS OWNER specification on it and the owner is set to SCHEMA OWNER, the user must also have IMPERSONATION permission on the owner of the target schema.

All permissions associated with the securable that is being transferred are dropped when it is moved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top