Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vgr.raju
Yak Posting Veteran
95 Posts |
Posted - 2006-08-23 : 02:51:50
|
| Hello Experts, I am having difficulty in forcing the fetching order of the input sql files in my Batch File.The command file picks up the files in the ascending order based on Names.This creates the Missing Dependency Errors.The batch file script:ECHO OFFset ServerName=%1set DatabaseName=%2set WorkDirectory =%3echo The ServerName used in applying this Build: %1echo The DatabaseName used in applying this Build:%2echo The directory used in the Build: %3echo: The Build Start time %date% %time%ECHO: Checking the existence of database: %2 in server: %1Echo: If not exists creating the Database: %2 in Server: %1set Query="IF NOT EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='%2') BEGIN CREATE DATABASE %2 END"sqlcmd -S %1 -d Master -Q %Query%echo: Checking the connection to the Server: %1 and Database: %2set qry ="set nocount on"sqlcmd -S %1 -d %2 -Q "%qry%"IF %Errorlevel% NEQ 0 goto FailureExit:Echo Applying the Scripts at Server: %1 and Database %2for %%B in (%3\*.sql) do (sqlcmd -S %1 -d %2 -i %%B)IF %Errorlevel% NEQ 0 goto FailureExit:REM: for %%B in (%3\.\*.sql) do (sqlcmd -S %1 -d %2 -i %%B)REM: IF %Errorlevel% NEQ 0 goto FailureExit:REM: for %%B in (%3\.\*.sql) do (sqlcmd -S %1 -d %2 -i %%B)REM: IF %Errorlevel% NEQ 0 goto FailureExit:Echo The Build successfully applied at Server: %1 and Database: %2Echo The Build completed Time %date% %Time%:FailureExit echo The build Cancelled at Server: %1 and Database: %2I would really helpful some one tells me how to force the fetching order of the SQL Input files?Thanks in advance!Raju |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2006-08-23 : 06:49:47
|
| The only thing I can think of is to have your files named so that they are picked up in order. This is more a BATCH file question than SQL.It is UGLY, but try and see if you name your files along the lines of:001.CreateSchema.SQL010.CreateTableParent.SQL011.CreateTableChild.SQL100.CreateSPA.sql101.CreateSPB.sql200.CreateFunctionX.sql300.CreateFKConstraintParentChild.sql400.CreateDefaultConstraintXXX.sql500.CreateLoginAndUser.sql600.CreateIndexTableParent1.sql601.CreateIndexTableChild1.sqletc. etc.Don't know if it will work though...*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2006-08-23 : 06:56:24
|
| Alternatively, have subdirectories, and process them in Order:...\Deployment\DBCreate...\Deployment\SchemaCreates...\Deployment\ReferenceDataTables...\Deployment\InstanceTables...\Deployment\PKConstraints...\Deployment\FKConstraints...\Deployment\DefaultConstraints...\Deployment\OtherConstraints...\Deployment\Indexes...\Deployment\StoredProcedures...\Deployment\Functions...\Deployment\LoginsAndUsers...\Deployment\ReferenceData...\Deployment\SQLServerAgentJobsI think that should work. Some things though - table creates must be without foreign key contraints inside the table definition - this removes the requirement for tables to be created in order. All FK contrainst are created, but as explicit 'alter table add constraints'- your file must be able to handle empty directories, then you can habe a static, default file strucutre for all DB projects...*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
vgr.raju
Yak Posting Veteran
95 Posts |
Posted - 2006-08-23 : 11:15:09
|
| Hello, Thanks for your quick response.I appended the sequence order with the file name and it works fine.Thanks!Raju |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2006-08-23 : 11:37:40
|
| Glad to hear it...*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
|
|
|
|
|