I have this batch file that outputs a list of all the tables to a file. I am looking for the command that will input this list and generate a whole list of drop statements to drop all the tables with?
:: droptables.bat
set SQLVER=100
if NOT EXIST "%PROGRAMFILES%\Microsoft SQL Server\100\Tools\BINN\osql.exe" (
@echo MS SQL Server 2008 not found.
set SQLVER=90
if NOT EXIST "%PROGRAMFILES%\Microsoft SQL Server\90\Tools\BINN\osql.exe" (
@echo MS SQL Server 2005 not found.
set SQLVER=80
if NOT EXIST "%PROGRAMFILES%\Microsoft SQL Server\80\Tools\BINN\osql.exe" (
@echo MS SQL Server is not yet installed.
pause
exit
)
)
)
@echo Your SQL Server version is %SQLVER% (100=2008,90=2005, and 80=2000)
if exist "%PROGRAMFILES%\Microsoft SQL Server\%SQLVER%\Tools\BINN\osql.exe" (
"%PROGRAMFILES%\Microsoft SQL Server\%SQLVER%\Tools\BINN\osql" -E
-d "%PROJECT%PD_FSDB_ECitation" -h-1 -Q "select name from sysobjects where
type='U' order by name;" -o tableList.txt
The above query needs to be changed to create a list of drop statements instead of just table names. The tableList.sql file is just a simple list of drop table statements.
After generating the queryList.sql, then I want to run it like so:
osql -E -h-1 -i C:\MyFolder\queryList.txt
I know there is a way to generate a list of SQL statements from a SQL statement but I don't remember how to do it.