My workflow with SQL often looks like that:

  • backup
  • hack, hack, hack
  • break something important
  • restore
  • repeat

To make life easier, I created three batch scripts: backup.bat, drop.bat and restore.bat, that wrap osql.exe to do the obvious. But there’s a problem. While number of apps I have to support in my day job increases, I need to remember more and more database names because these scripts are dummy and need explicit, correct parameters. I decided that enough is enough and created smarter PowerShell module that includes tab completion for available databases and automatically restores last backup if called without parameters.

New-SqlBackup -dbName AdventureWorks
Restore-SqlBackup AdventureWorks

Please make note that this module depends on SQL Server Management Objects API, so you need to have Client Tools SDK for SQL Server (part of SQL Server installation) or Shared Management Objects from the SQL Server feature pack.

Download

SqlHelpers PowerShell module is available on github