// SQL Server error reference

SQL Server error 5030: Database couldn't be exclusively locked

An ALTER DATABASE operation such as a rename or collation change needs exclusive access, but other sessions are using the database.

Error number
5030
Severity
16
Category
Names and objects
Error message
The database %.*ls could not be exclusively locked to perform the operation.

What it means

Some database-level changes, such as ALTER DATABASE ... MODIFY NAME or changing the database collation, require that no other session is using the database. If one is, SQL Server raises 5030.

Common causes

  • Other connections to the database, including your own query window or Object Explorer.
  • Background tasks or applications that keep connections open.

How to fix it

  1. Take the database into single-user mode for the change.

    USE master;
    ALTER DATABASE SalesDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    ALTER DATABASE SalesDb MODIFY NAME = SalesDb2025;
    ALTER DATABASE SalesDb2025 SET MULTI_USER;
  2. Schedule the change in a maintenance window, since ROLLBACK IMMEDIATE rolls back other users' open transactions.

Related errors

More names and objects errors

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.

// fewer errors, faster fixes

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.