I log in to SSMS with one set of credentials, no problem. Then I want to access several databases in a script but one of the databases requires different credentials. Is there a way to specify different credentials within the script when accessing a database?
Yes, there is a way.
Try with EXECUTE AS
, see the snippet below.
EXECUTE AS LOGIN = 'your login name';
EXECUTE AS USER = 'your user name';
See more on EXECUTE AS (Transact-SQL)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.