15023: User already exists in the current database
SQL ServerWhat 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');
More from this engine
- 8114Error converting data type X to Y
- 1204The instance of the SQL Server Database Engine cannot obtain a LOCK resource
- 3906Failed to update database because the database is read-only
- 18452Login failed. The login is from an untrusted domain and cannot be used with Windows authentication
- 605Attempt to fetch logical page belongs to a different allocation unit
- 4922ALTER TABLE ALTER COLUMN failed because one or more objects access this column
- 7202Could not find server 'name' in sys.servers