Dismount-DbaDatabase (alias Detach-DbaDatabase)

This command detaches one or more SQL Server databases. If necessary, -Force can be used to break mirrors and remove databases from availability groups prior to detaching.

Screenshots

Dismount-DbaDatabase aka Detach-DbaDatabase

Examples

Detach-DbaDatabase -SqlInstance sql2016b -Database SharePoint_Config, WSS_Logging

Detaches SharePoint_Config and WSS_Logging from sql2016b

Get-DbaDatabase -SqlInstance sql2016b -Database ‘PerformancePoint Service Application_10032db0fa0041df8f913f558a5dc0d4’ | Detach-DbaDatabase -Force

Detaches ‘PerformancePoint Service Application_10032db0fa0041df8f913f558a5dc0d4’ from sql2016b. Since Force was specified, if the database is part of the mirror, the mirror will be broken prior to detaching. If the database is part of an availability group, it will first be dropped prior to detachment

Get-DbaDatabase -SqlInstance sql2016b -Database WSS_Logging | Detach-DbaDatabase -Force -WhatIf

Shows what would happen if the command were to execute (without actually executing the detach/break/remove commands)