DBAtlas · Database operations atlas

15023: User already exists in the current database

SQL Server

What does it mean?

While adding a new user to the database, a user with the same name was found to already exist in that database. It also appears when mapping a login to an existing user (orphaned users).

Why does it happen?

Typically, when a database is restored from backup to a different server, login SIDs do not match the database users (orphaned users). Trying to add the same name again with CREATE USER, or trying to set up the login-user mapping manually, raises this error.

How to fix it

Remap the orphaned user to the existing login: ALTER USER app_user WITH LOGIN = login_name; (recommended over the legacy sp_change_users_login). If the user is genuinely redundant: DROP USER app_user; To find orphans: SELECT dp.name FROM sys.database_principals dp LEFT JOIN sys.server_principals sp ON dp.sid = sp.sid WHERE sp.sid IS NULL AND dp.type IN ('S','U');

Open in DBAtlas →

More from this engine