October 13, 2005 at 6:35 pm
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
October 13, 2005 at 8:09 pm
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
October 14, 2005 at 12:41 am
Couple of caveats w/ setuser, only works with SQL Logins (no windows/integrated security accounts) and must be executed by a sysadmin/sa.
October 16, 2005 at 1:35 pm
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