SQL Server error 15023: User, group, or role already exists
CREATE USER or a similar statement named a principal that already exists in the database, often an orphaned user left behind by a restore.
- Error number
15023- Severity
- 16
- Category
- Permissions
What it means
Database principal names are unique per database. Error 15023 appears when you create a user, role or group that is already there. After restoring a database to another server, the old database user is usually still present but no longer linked to a login, and trying to create it again fails with 15023.
Common causes
- Running a setup script twice.
- Restoring a database to a new server: the database user exists but is orphaned, because the new server's login has a different SID.
- Mapping a login to a database in SSMS when a user of that name already exists.
How to fix it
-
If the existing user is orphaned, link it to the login instead of creating a new one.
ALTER USER app_user WITH LOGIN = app_user;
-
Make setup scripts idempotent.
IF DATABASE_PRINCIPAL_ID(N'app_user') IS NULL CREATE USER app_user FOR LOGIN app_user;
Related errors
15151Object doesn't exist or no permission916Login can't access the database2714There is already an object named
More permissions errors
229Permission denied on object262Permission denied in database15025The server principal already exists15138User owns a schema, cannot be dropped
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.