How to delete MSSQL database using sqlcmd

I have multiple databases created by POCO approach of website building and I want to delete those. However I get error.

Command

sqlcmd -S .\SQLEXPRESS -q "drop database aspnet-ORData-20120910180110"

Error

Msg 102, Level 15, State 1, Server MY-PC\SQLEXPRESS, Line 1
Incorrect syntax near '-'.

Solution 1:

Try this:

sqlcmd -S .\SQLEXPRESS -q "drop database [aspnet-ORData-20120910180110]"

Note the square brackets around the database name. Without them the dashes ("-") are seen as tokens instead of part of the database name and the parser will want to do math. The command parser interprets anything inside square brackets as a literal.