我写了这份简便的批量文件,但如果我输入包含“-”性质的数据库名称,则失败。 难道不确切地说,为什么,但我希望我能这样说?
:: open DB batch file
@echo off
:: starts Sql Server Management Studio Express 2005
:: and opens it to a specific database with query
:: window already open
cls
:SHOWDBNAMES
echo Database names detected on this system:
echo.
"%PROGRAMFILES%Microsoft SQL Server90ToolsBinnOSQL.EXE" -h-1 -S . -E -Q "SELECT CAST(name AS VARCHAR(30)) FROM sysdatabases"
@echo.
set DBNAME=
set /P DBNAME=What database name would you like to open (choose from list)?
if "%DBNAME%" == "" (
echo.
echo I don t recognize your selection. Try again.
goto SELECTDB
)
:SHOWTABLES
cls
echo.
echo Tables that you can query from %DBNAME% are:
echo.
"%PROGRAMFILES%Microsoft SQL Server90ToolsBinnOSQL.EXE" -h-1 -S . -E -Q "use [%DBNAME%];SELECT CAST(name AS VARCHAR(30)) FROM sys.Tables ORDER BY name"
echo.
:RUNIT
sqlwb.exe -nosplash -S . -E -d %DBNAME%
pause
:EOF