I\'m trying to change the owner of a table:
sp_changeobjectowner \'OWNER.TABLENAME\', \'dbo\'
But when executing I get the error message:
The correct way to do this in SQL Server 2005 and up is to stop thinking about the prefix as an "owner." The sp_changeobjectowner procedure has been deprecated since SQL Server 2005, and you should instead be using schema DDL, e.g.:
ALTER SCHEMA dbo TRANSFER [current_owner].tablename;
To check the current "owner" (this may return multiple rows if you have more than one tablename
in multiple schemas):
SELECT s.name
FROM sys.schemas AS s
INNER JOIN sys.tables AS t
ON s.[schema_id] = t.[schema_id]
WHERE t.name = N'tablename';
Also be sure that you spell the object correctly. In a case-sensitive collation, for example, TABLENAME
and tablename
are not the same object, and spelling it with InCorrEcT CaSe could also lead to this error.