Thor Logo dbatools

Delete

Remove-DbaDatabase

Chrissy LeMaire (@cl), netnerds.net

Remove-DbaDatabase View Source Chrissy LeMaire (@cl), netnerds.net Windows, Linux, macOS Synopsis Removes user databases using multiple fallback methods to handle stuck or locked databases. Description Removes user databases by attempting three different drop methods in sequence until one succeeds. First tries the standard KillDatabase() method, then attempts to set the database to single-user mode with rollback immediate before dropping, and finally uses the SMO Drop() method. This approach handles databases that are stuck due to active connections, replication, mirroring, or other locks that prevent normal removal.

Read more

Remove-DbaDatabaseSafely

Rob Sewell (@SQLDBAWithBeard), sqldbawithabeard.com

Remove-DbaDatabaseSafely View Source Rob Sewell (@SQLDBAWithBeard), sqldbawithabeard.com Windows, Linux, macOS Synopsis Removes databases after creating verified backups and testing restore procedures. Description Performs a comprehensive database removal workflow that validates database integrity, creates verified backups, and tests restore procedures before permanently removing databases. This function runs DBCC CHECKDB to verify database health, creates a checksummed backup to a specified location, generates a SQL Agent job for automated restore testing, drops the original database, executes the restore job to verify backup integrity, performs another DBCC check on the restored database, and finally removes the test database.

Read more

Remove-DbaDbBackupRestoreHistory

IJeb Reitsma

Remove-DbaDbBackupRestoreHistory View Source IJeb Reitsma Windows, Linux, macOS Synopsis Removes backup and restore history records from MSDB database to prevent excessive growth Description Removes backup and restore history records from MSDB database tables to prevent them from consuming excessive disk space and degrading performance. Over time, these history tables can grow substantially on busy SQL Server instances with frequent backup operations. Works in two modes: server-level cleanup removes records older than a specified retention period (default 30 days), while database-level cleanup removes the complete backup/restore history for specific databases.

Read more

Remove-DbaLogin

Chrissy LeMaire (@cl), netnerds.net

Remove-DbaLogin View Source Chrissy LeMaire (@cl), netnerds.net Windows, Linux, macOS Synopsis Removes SQL Server logins from target instances Description Removes one or more SQL Server logins from specified instances using the SMO Drop() method. This function handles the complete removal process including dependency checks and provides proper error handling when logins cannot be dropped due to existing sessions or database ownership. Use the -Force parameter to automatically terminate active sessions associated with the login before removal, which is useful when cleaning up test environments or decommissioning user accounts.

Read more