views:

9

answers:

1

I named a schema wrong, and all the tables are created with a schema of a wrong name. So I created a one, and use alter schema to transfer the tables over.

First problem is, SQL Server fails when I try to drop the wrong schema, second, although users were created with the new schema as default, I figure I could simply say

select * from table1, 

rather than

select * from myschema.table1, 

but it doesn't work. I have to be explicit. Any ideas what's going on? The weirder thing is, the old user that was created with the wrong schema as default, now is not able to change it. It's kind of frustrating. Please help.

+1  A: 

Can you try doing the following :

ALTER USER userName  
WITH DEFAULT_SCHEMA =myschema

Assuming "myschema" is the new schema that you want the user to default to.

I know you mentioned that the new user is created with the new schema but if that is the case, then you should not see this kind of error. So something seems to have gone wrong. Explicitly setting the default schema might correct this.

In general,

  1. The default schema of your login session in the current database is the default schema assigned to the current database level principal - database user.

  2. If you are referring to an object in the default schema, you do not need to specify the schema name.

  3. If you are referring to an object outside the default schema, you must specify the schema name.

For more details regarding the schema for session etc maybe this will also help

InSane
It works, and if I go to user property, it does show the new default schema. However, a select query doesn't work unless I explicitly say select * from new_default_schema.table1, which defeats my purpose of applying a default schema. Any ideas?
Haoest
Just to absolutely make sure - are you sure you are connecting with this same user. Can you maybe do a PRINT User_Name(); instead of your select - to verify the username being used by the connection?I know it may sound silly but sometimes it helps to re-check especially in a scenario like yours...which honestly doesnt seem to make sense :-)
InSane
oh shit. I've been using the same query tab although I explicitly say disconnect from the object explorer, so basically I was doing query on the old user credential this whole night. And for that same reason I can't delete the old schema because the session is holding on to it. Worst night ever.
Haoest
:-) :-) I think that its something thats happened to the best of us!! Glad to help!
InSane