Change Default Schema for a Session (not a user)

  • I would like to change the default schema programatically for the session the code is running in, is there a way to do this similar to the below?

    Alter Session set default schema = 'dbo'

    Select * from Table1 --This query pulls data from Table1 in the dbo schema

    Alter Session set default schema = 'client'

    Select * from Table1 --This query pulls data from Table1 in the client schema

    Thanks,

    Carleton

  • As far as I know there is no "default schema" for a session. But you can set a default schema for your user in every database it has access to.

  • I did realize that I can assign a default schema to a user, but what I was searching for was a statement that would allow me to change the default just for the session.

    I just found an enhancement request on Mircosoft's site. Someone was asking that the USE statement be expanded to include changing the context of the default schema. Looks like I'll have to wait on this.

    Thanks,

    Carleton

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

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