SQL Server Error 988 occurs when the database lacks a valid owner or the current owner is no longer a valid login on the server. To fix this immediately, you must assign a valid system administrator (such as 'sa') as the database owner using the ALTER AUTHORIZATION command. This error typically triggers when a database is restored from another server or when the login that originally created the database has been deleted from the instance.

What You'll Need

  • SQL Server Management Studio (SSMS) or a similar SQL query tool.
  • A login account with sysadmin privileges (such as the 'sa' account or your own Windows Administrator account).
  • The exact name of the database that is triggering the error.

Step-by-Step

  1. Launch SQL Server Management Studio (SSMS): Open the application and connect to the SQL Server instance where the problematic database is hosted. Ensure you are logging in with an account that has sysadmin permissions, as changing database ownership requires high-level security clearance.
  2. Identify the Affected Database: Locate the database in the Object Explorer on the left-hand side. If you cannot expand the database folder due to the error, you will need to perform the fix using a T-SQL query window rather than the graphical user interface.
  3. Open a New Query Window: Click the "New Query" button in the top toolbar. Ensure that the available databases dropdown menu (located in the top left of the toolbar) is set to "master". This is critical because you cannot run ownership changes while connected to the database that is currently inaccessible.
  4. Verify Current Ownership: Before applying the fix, you can check who the current owner is by running the following query: SELECT name, suser_sname(owner_sid) AS OwnerName FROM sys.databases WHERE name = 'YourDatabaseName';. Replace 'YourDatabaseName' with the actual name of your database. If the OwnerName column is NULL or shows a SID that does not match an existing login, the cause of Error 988 is confirmed.
  5. Execute the Authorization Change: To resolve the error, you must assign a valid login as the owner. The most stable choice is usually the 'sa' (System Administrator) account. Type the following command into the query window:
    ALTER AUTHORIZATION ON DATABASE::[YourDatabaseName] TO [sa];
    Replace [YourDatabaseName] with the name of your database. Keep the square brackets if your database name contains spaces or special characters.
  6. Run the Command: Press F5 or click the "Execute" button. You should see a message stating "Commands completed successfully."
  7. Test Access: Try to expand the database in the Object Explorer or run a simple SELECT query against a table in that database. The Error 988 should now be gone, as the database now has a valid, authenticated owner.
  8. Verify the Change: Run the verification query from Step 4 again. The OwnerName should now reflect 'sa', confirming the link between the database and the server instance is restored.

Common Mistakes

One of the most frequent mistakes is attempting to run the ALTER AUTHORIZATION command while the session is connected to the database you are trying to fix. Because Error 988 prevents access to the database, the command will often fail or the session will be disconnected before the change can be applied. Always ensure your connection context is set to the master database before executing the fix.

Another common error is using sp_changedbowner. While this stored procedure was used in older versions of SQL Server, it is deprecated. Modern versions of SQL Server use ALTER AUTHORIZATION. Using deprecated procedures can lead to unexpected behavior or errors in newer versions of the software.

Users also frequently forget to check if the new owner actually exists on the current server instance. If you attempt to change the owner to a specific Windows user account that has not been added as a login to the SQL Server instance, the command will fail. This is why using 'sa' is the recommended best practice for resolving this specific error, as 'sa' is guaranteed to exist on every SQL Server instance.

Tips

When restoring databases from a backup created on a different server, always make a habit of checking the database ownership immediately after the restore. The Security Identifier (SID) of the owner on the source server will not match the SID on the destination server, even if the username is identical. This "orphaned user" scenario is the primary cause of Error 988.

For production environments, consider creating a dedicated low-privilege login for database ownership if your security policy forbids using the 'sa' account. However, ensure this account is a permanent login that will not be deleted during routine employee offboarding, as deleting the owner account will trigger Error 988 again for all databases they owned.

If you are managing multiple databases and suspect several might have this issue, you can write a script to loop through all databases in sys.databases and check for NULL owners, allowing you to fix them in bulk rather than one by one.

Troubleshooting

If the ALTER AUTHORIZATION command fails with a "permission denied" error, it means the account you are using to run the query does not have the CONTROL permission on the database or the sysadmin server role. You must log in as a member of the sysadmin fixed server role to perform this action.

If you receive an error stating that the login 'sa' is disabled, you cannot assign it as the owner. In this case, you must first enable the 'sa' account through the Security > Logins menu in SSMS or by using the ALTER LOGIN [sa] ENABLE command. Alternatively, assign ownership to your own current Windows admin login.

In rare cases, the database may be in a "Restoring" or "Recovery Pending" state. If the database is not online, you cannot change the authorization. You must first complete the restore process or bring the database online using RESTORE DATABASE [YourDatabaseName] WITH RECOVERY before you can resolve the ownership issue.

If the error persists after changing the owner, check for "orphaned users" inside the database. While Error 988 is about the database owner, internal users may also be disconnected from their server logins. You can fix these by using the ALTER USER [UserName] WITH LOGIN = [LoginName] command to re-map the database user to the server login.

Frequently Asked Questions

Why did this error happen after a database restore?

When a database is moved between servers, the owner's unique Security Identifier (SID) is carried over. Since the destination server does not recognize that specific SID, the database is left without a valid owner, triggering Error 988.

Is it safe to make 'sa' the owner of all my databases?

Yes, it is a common and safe practice. Making 'sa' the owner ensures that the database always has a valid owner regardless of which individual employees leave the company or which Windows accounts are renamed.

Can I fix this using the SSMS graphical interface?

Usually, no. Because Error 988 prevents you from accessing the database properties, the GUI will often throw the same error when you try to open the database settings. Using a T-SQL query while connected to the master database is the most reliable method.

Does changing the owner affect the data inside the tables?

No. Changing the database owner only affects the administrative metadata of the database. It does not modify, delete, or alter any of the actual data stored within your tables or views.

What is the difference between a database owner and a sysadmin?

A sysadmin has full control over the entire SQL Server instance, including all databases. A database owner (dbo) has full control over one specific database but may have no permissions on other databases or the server itself.

Will this error affect my application's connection string?

The error itself doesn't change your connection string, but it prevents the connection from succeeding. Once the owner is fixed, your application should be able to connect again without any changes to the connection string.