Sometimes, either when creating a new Site Collection or when mounting a database using the
Mount-SPContentDatabase PowerShell Cmdlet, or in any other case where something might go wrong, a content database may become a ghost one.
A content database becomes a ghost database when the
Get-SPContentDatabase PowerShell Cmdlet returns any of the following:
1. No Web Application name
Id : DATABASE_GUID Name : CONTENT_DATABASE_NAME WebApplication : Server : DB_SERVER_NAME CurrentSiteCount : 1
2. No Content Database name
Id : DATABASE_GUID Name : WebApplication : SPWebApplication Name=WEB_APPLICATION_NAME Server : DB_SERVER_NAME CurrentSiteCount : 1
Not the exact same situation, but similar. Again it’s a ghost database.
The remedy is to delete the database. Delete in this situation does not mean delete the database physically from disk or from database server. It means to make SharePoint forget about the database.
In any case, having the database name or Id, one solution could be the
SPContentDatabase.Delete() as in the following example:
$DB = Get-SPContentDatabase CONTENT_DATABASE_NAME_OR_GUID $DB.Delete()
The other solution is the
SPWebApplication.ContentDatabases.Delete() which accepts a database GUID.
$WebApp = Get-SPWebApplication WEB_APP_URL $WebApp.ContentDatabases.Delete(CONTENT_DATABASE_GUID)