Wednesday, 29 June 2011

Deleting a database with sqlcmd

sqlcmd -s <servername> -q "DROP DATABASE <database name>"
OR
sqlcmd -s ./<sqlserver instance name> -q "DROP DATABASE <database name>"

Examples:
sqlcmd -s dbserver -u username -p password -q "DROP DATABASE products"
sqlcmd -s localhost -q "DROP DATABASE products" 
sqlcmd -s ./MSSQLSERVER -q "DROP DATABASE products" 



3 comments:

Anonymous said...

Should that be an upper case S for the server name/instance, ie. -S?

Anonymous said...

U and P should be upper also.

Anonymous said...

Does it set SINGLE_USER mode? Does it work if DB is busy?