Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server multiple schema object issues

I have database that has multiple schemas and objects under them. I want to consolidate the objects into one schema.

I tried

ALTER SCHEMA dbo TRANSFER <custom_schema>.<table_name>

I get an

object already exists message

However, I can't see it in the Management studio and

SELECT * from dbo.<table_name>

returns

object does not exist.

Looks like some system table entry is out of whack. I looked at sysobjects and it has only one entry for . Any suggestions on how to trouble shoot/ fix this issue is welcome.

Note: I can create a synonym

CREATE SYNONYM dbo.<table_name> FOR <custom_schema>.<table_name>

works fine

like image 954
shikarishambu Avatar asked Nov 19 '10 16:11

shikarishambu


1 Answers

According to this MSDN page your issue may be caused by a duplicate primary key name. i.e. your table_name's primary key name conflicts with a primary key name already defined within some other table in dbo.

To resolve this issue, rename the primary key for the table that you want to move. Use a name that does not appear as a primary key in the destination schema.

like image 54
Jeff Swensen Avatar answered Sep 22 '22 12:09

Jeff Swensen