How to Set Current Schema in SQLServer ?

  • Hello all ! How do I set the current schema in SQLServer ? For example: There is a table named "Partner" that was created using schema "foo". I am logged as "bar", that has no privileges but querying the table. I have to put the alias in front of the name of the table as in "Select * from foo.Partner" , however, as i am running from an application that has users pre-configured, I don't want people to use the schema in front of their tables. How do I set that ? In Oracle, the command is "alter session set CURRENT_SCHEMA = bar"

  • sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'

    so

    sp_changeobjectowner 'Partner', 'bar'

    and so no schema needed do

    sp_changeobjectowner 'Partner', 'dbo'

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • That's the point: I don't want to change the object owner, just for the session. It just gives me the messsage "User does not have permission to perform this action." with my query user.

  • Sorry, I know of no way off hand to do it for the session. You could create a view to the object with same name and dbo as owner I believe will do the trick.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply