--1, preparation work. Create two login names
Create Login Login1 with password= ' 123456 ';
Create Login Login2 with password= ' 123456 ';
--Create two user names U1 and U2 in the Studentcourse database and associate them with the two logins above, respectively
Use Studentcourse
Go
Create User U1 for Login Login1;
Create User U2 for Login Login2;
--2, fast switching users
--"View Current User"
Print Current_User;
--"Analog Access User: U1"
Execute as user= ' U1 ';
Print Current_User;
--"Switch back to dbo user"
Revert;
Print Current_User;
--"Analog Access User: U2"
Execute as user= ' U2 ';
Print Current_User;
--"Switch back to dbo user"
Revert;
Print Current_User;
--Delete the login and user name for the test
Drop Login Login1;
Drop Login Login2;
Drop User U1;
Drop User U2;
For SQL code implementation of user creation, as well as switching between different users landing