Sunday, April 17, 2011

SQL Server Databases without Owners

Have you ever come across the following error when running exec sp_helpdb?


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


The next thing to check is whether the following T-SQL code returns any rows


select name from master..sysdatabases where sid is NULL


The result is those databases that are associated with owners who no longer exist (or existed another server elsewhere if the databases were restored from another server).


The solution is simple enough:


exec sp_changedbowner 'sa'


Sometimes, due to orphaning, this can still fail. Just run sp_changedbowner to any valid user. Afterwards, changing it to SA should work too, if you wish.


http://www.bigresource.com/MS_SQL-sp_helpdb-Problem-plz-help-Ruk7t4Q1.html is a good blog on this particular problem.

No comments: