SQL Server Error 688 occurs when you attempt to perform a database operation—such as dropping a table, altering a schema, or switching a database to single-user mode—while there is an active transaction or an open connection preventing the change. To fix this, you must identify the session ID (SPID) holding the active transaction and terminate that session using the KILL command, or wait for the transaction to commit or roll back naturally.

What You'll Need

  • SQL Server Management Studio (SSMS) or another SQL query tool.
  • Administrative privileges (sysadmin or processadmin role) to view and terminate other users' sessions.
  • Access to the database instance where the error is occurring.

Step-by-Step

  1. Identify the Blocked Operation: First, confirm exactly which action triggered Error 688. This usually happens during a ALTER DATABASE command or when trying to drop a table that is currently being accessed by a long-running query or an uncommitted transaction. Note the database name involved in the operation.
  2. Locate Active Sessions: You need to find the Session ID (SPID) that is keeping the transaction active. Open a new query window in SSMS and run the following command to see all active requests and their status:
    SELECT spid, status, loginame, hostname, dbid, cmd FROM sys.sysprocesses WHERE dbid = DB_ID('YourDatabaseName');
    (Replace 'YourDatabaseName' with the actual name of your database).
  3. Analyze Transactional State: If the previous list is too broad, use DBCC OPENTRAN to find the oldest active transaction in the database. Run:
    DBCC OPENTRAN('YourDatabaseName');
    This command will return the SPID of the transaction that has been open the longest. This is often the culprit behind Error 688 because it holds locks that prevent schema changes.
  4. Verify the Session Activity: Before killing a session, check what that session is actually doing to avoid interrupting a critical data update. Run:
    DBCC INPUTBUFFER(SPID_Number);
    (Replace SPID_Number with the ID found in the previous steps). This shows the last SQL command sent by that session.
  5. Terminate the Active Session: Once you have identified the SPID causing the conflict, use the KILL command to force the session to close and roll back its transaction. Run:
    KILL SPID_Number;
    For example, if the SPID is 54, you would run KILL 54;. This releases all locks held by that session.
  6. Retry the Original Operation: Now that the active transaction is cleared, return to your original task (e.g., dropping the table or altering the database). The operation should now proceed without the Error 688 message.
  7. Verify Database State: If you were attempting to put the database into SINGLE_USER mode, verify the status by checking the database properties in SSMS or running SELECT name, user_access_desc FROM sys.databases WHERE name = 'YourDatabaseName';.

Common Mistakes

One of the most frequent mistakes is attempting to kill system processes. SQL Server has internal background processes (usually SPIDs lower than 50) that manage the engine. Attempting to KILL these can lead to instance instability or unexpected restarts. Always ensure the SPID you are targeting is a user session.

Another common error is failing to check the DBCC INPUTBUFFER before killing a process. In a production environment, killing a session that is halfway through a massive data migration or a complex index rebuild can trigger a lengthy rollback process. If the transaction was very large, the database may remain locked while it rolls back the changes, potentially making the system unavailable for longer than if you had simply waited for the process to finish.

Users also frequently forget that multiple sessions might be active. If you kill one SPID and Error 688 persists, it means there are other active transactions. You must repeat the identification process until all conflicting sessions are cleared.

Tips

To avoid Error 688 when switching a database to SINGLE_USER mode, use the WITH ROLLBACK IMMEDIATE clause. This tells SQL Server to immediately terminate all existing connections and roll back any uncommitted transactions, rather than waiting for users to disconnect manually. The syntax is: ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

If you frequently encounter this error during maintenance, consider scheduling your tasks during low-traffic windows. This reduces the likelihood of overlapping transactions and minimizes the impact on end-users when you have to kill sessions.

For developers, ensure that your application code always closes connections and commits or rolls back transactions in a finally block. Many Error 688 instances are caused by "orphaned transactions"—sessions where the application crashed or timed out without explicitly closing the SQL transaction, leaving the lock active on the server.

Troubleshooting

If the KILL command does not seem to work immediately, check the status of the SPID again using sys.sysprocesses. You may see the status listed as "KILLED/ROLLBACK". This means SQL Server is currently undoing the changes made by that transaction to maintain data integrity. You cannot force this process to speed up; you must wait for the rollback to complete before the locks are released.

If you cannot find the SPID using DBCC OPENTRAN but the error persists, there may be a distributed transaction (MSDTC) involved. Check the Distributed Transaction Coordinator logs or use SELECT * FROM sys.dm_tran_active_transactions to find transactions that span multiple servers or databases.

In extreme cases where the database is completely unresponsive and you cannot run KILL commands, you may need to restart the SQL Server service. Warning: Restarting the service will disconnect all users and force a recovery process for all databases upon startup, which can take significant time depending on the size of the transaction logs. This should be a last resort.

Frequently Asked Questions

Why does Error 688 happen during database backups?

While backups usually don't trigger this, certain types of exclusive locks required for specific maintenance tasks during a backup window can conflict with active user transactions, leading to this error.

Is it safe to use KILL on a production server?

It is generally safe, but it should be done with caution. Killing a session will roll back any uncommitted work, meaning the user who was running the query will lose their unsaved changes.

Can this error be caused by a deadlock?

Not exactly. A deadlock is when two sessions block each other and SQL Server automatically kills one. Error 688 is a manual block where the system is telling you that an active transaction is preventing a specific administrative action.

How can I prevent this error in the future?

Implement strict timeout settings in your application and ensure that all database connections are wrapped in try-catch-finally blocks to ensure transactions are always closed.

Does this error mean my data is corrupted?

No, Error 688 is a concurrency and locking issue, not a data corruption issue. It simply means the database is protecting the integrity of an active transaction by preventing you from changing the structure of the database while that transaction is running.