SQL Express: Quick results using SQLCMD

I’ve been playing with some of VMware’s new products in my homelab, and have been using SQL Express 2008 R2 as part of the set-up / installations. In building and burning installs, I’ve often found the need to build and delete databases quickly.

Now – instead of using SQL Management Studio Express Edition to manage this (mostly DB drop) avtivity, I’ve found a much quicker method: Use SQLCMD.

To connect to a local SQL Express instance \SQLEXPRESS:

C:\sqlcmd -S.\SQLEXPRESS

To list existing databases within the default instance:

1> sp_databases
2> go

To ‘use’ a particular database (e.g. DISCO):

1> use DISCO
2> go

To delete a particular database (e.g. DISCO):

1> drop database [DISCO]
2> go

(with the last delete command, note the square brackets around the DB name. Without these, an error will result).

These might seem simple commands, but if you’ve not used SQL or SQL Express before, or you do lots of building in your homelab with SQLExpress, this might just save some time!

Jeremy loves all things technology! Has been in IT for years, loves Macs (but doesn't preach to others about their virtues), loves virtualization (and does shout about it's virtues), and sometimes skis, bikes and directs amateur plays!

Leave a Reply

Your email address will not be published. Required fields are marked *