You may receive an error while executing sp_helpdb


While executing sp_helpdb, you may receive an error similer to below:

Msg 515, Level 16, State 2, Procedure sp_helpdb, Line 53
Cannot insert the value NULL into column 'owner', table 'tempdb.dbo.#spdbdesc___________________________________________________________________________________________________________00010001D881'; column does not allow nulls. INSERT fails.
The statement has been terminated.

This error is thrown because one of the database does not have owner defined with it and hence sp_helpdb can not work on that database. This error can be thrown if you are using sp_helpdb [DatabaseName] to get properties of that particular database or sp_helpdb to get properties of all databases residing on that SQL instance. As the internal table used by sp_helpdb does not allow value of owner column as “Null”, this error is thrown.

Solution:

Resolving this is very straight forward. Identify the database/s whioh have the owner missing and then execute below code to assign them an owner:

EXEC sp_changedbowner 'New_Owner'
 
Typically as a part of good practice you can have sa as the database owner unless you have a valid reason to assign some other account as owner.

Comments