When restoring database from once instance to another one sometimes has to relink SQL Server Logins to the Database User.
This is normally achieved with one of the following procedures.
Deprecated sp_change_users_login Stored Procedure
use <database>
go
sp_change_users_login 'Update_one', '<datbase_user>', '<sql server login>'
go
ALTER USER Command
use <database>
go
ALTER USER [<datbase_user>] WITH LOGIN = [<sql server login>]
go
These commands will re-link an orphaned Database User to a corresponding SQL Server Login.
Question
Is it possible to break this relationship without deleting either the SQL Server Login or the Database User?
Reasons
- Deleting the Database User will remove the permissions in the database.
- Deleting the SQL Server Login will remove the password. (Hashed value; unknown to DBA)
- I linked a Database User to a SQL Server Login that is a Windows System Account.
Research
I have had a look at the sys.database_principals
and sys.server_principals
DMVs, but they are not modifiable.
Best Answer
You can accomplish this in a roundabout way be creating a temporary login, remapping the user to the temporary login, and then dropping the temporary login. For a SQL login:
For a Windows authenticated login/user, you would need to create a temporary Windows account, and then delete it, so it's not a 100% T-SQL solution: