Change current User

  • Hi all,

    Is there a way to change the current user in T-SQL?

    I need to be able to run certain parts of a script as different users, so rather then re-connecting in Query Analyzer and running different scripts, I would like one script to change users while executing.

    Is this possible? if so how?

    Cheers,

    Shawn

  • not sure why you want to do this unless you want create objects under different users...

     

    setuser user1

    go

    ....TSQL

    setuser

    go

     

    setuser user2

    ....TSQL

    setuser

    go

     

  • Couple of caveats w/ setuser, only works with SQL Logins (no windows/integrated security accounts) and must be executed by a sysadmin/sa.

     

  • thanks guys, this was just what I was looking for. I knew it had to be there somewhere, just couldn't fiqure out what it was called.

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

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