Below is my code in batchfile:
for %%f in (%~dp0*.sql) do (
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -I -i "%%f" >>TsDeploy.txt 2>&1
)
the question is there is one file in that set must be NOT Run as first one.(cause the others is script file about create Table,that one is to insert data into table ).
How Should I do to achieve the goal in ONLY ONE batchfile?
You could rename the sql file that must not run first so that it sorts to the end (prefix with z?).
Or you could do something like
for %%f in (%~dp0*.sql) do (
if "%~nxf" neq "fileNameNotToRunFirst.sql" (
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -I -i "%%f" >>TsDeploy.txt 2>&1
)
)
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -I -i "%~dp0fileNameNotToRunFirst.sql" >>TsDeploy.txt 2>&1
Or you could create a master sql script that calls each of the others in the proper order, as described in How to Run a Series of T-SQL Scripts in a Specific Order