A very old question, but since Google brought me here, I will add a solution that I found useful:
Step 1. Create a user for each scheme that you need to use. For example. "User_myschema"
Step 2. Use EXECUTE AS to execute SQL statements as the required schema user.
Step 3. Use REVERT to return to the original user.
Example: Suppose you have a table "mytable" present in the scheme "otherschema", which is not your default scheme. Running "SELECT * FROM mytable" will not work.
Create a user named "user_otherschema" and set thisschema to the default value of "otherschema".
Now you can run this script to interact with the table:
EXECUTE AS USER = 'user_otherschema'; SELECT * FROM mytable REVERT
Return statements reset the current user, so you become yourself again.
Link to the EXECUTE AS document: https://docs.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql?view=sql-server-2017
Culme Sep 04 '19 at 11:39 on 2019-09-04 11:39
source share