SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deploying Scripts with SQLCMD


Deploying Scripts with SQLCMD

Author
Message
peter_wong
peter_wong
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 46
We have been using isql and sqlcmd (recently) for the past 8 years to deploy stored procedures, triggers, functions, views, scripts to our customers and recently to our QA team.

In our release script (or batch files), we will pass in information like server, database, userid and password. In addition, we also use this script to verify the release before applying so that we will not accidentally overwrite the database.

We even go to the stage whereby we have different customers running different SQL Server version and hence will need to use either isql or sqlcmd.
Paresh Motiwala
Paresh Motiwala
SSC-Addicted
SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)

Group: General Forum Members
Points: 454 Visits: 314
I have another challenge.
Every month, I get about 15-20 scripts to be run against a database in Test Environment.
The scripts are numbered sqlscript1-15 or 30.

I somehow cannot get SQLCMD to work for it.
Has anybody, had success doing that.

If this works, I need to run the same scripts against Production.
Saving of output is also desired.
I can of course create a batch file with all scripts names hard coded, but then....there is no challenge.

Any help is welcome.
Paresh Motiwala
Boston



danpep
danpep
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 50
When I first needed to script my releases about 10 years ago, I started developing an app to do it for me. I have rewritten this app a number of times and I think it is time to share it now.

This free .Net app allows you to deploy multiple commands/script files to multiple SQL Servers within a transaction.

Read about and download it here: www.sqldart.com.

I'm still busy working on the web site/documentation, but I would appreciate any feedback in the meantime.



yordan.georgiev
yordan.georgiev
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 47
:: Tested on Win7 and Sql Server 2008
:: THIS SCRIPT GOES TO ALL SUBFOLDERS AND RUNS THE
:: YOU NEED THE FOLLOWING FOLDER STRUCTURE:
:: ROOT - THIS IS WHERE THIS FILE IS + THE FOLLOWING SUBFOLDERS
:: --0.BackUp
:: --1.Mixed
:: --2.Tables
:: --3.StoredProcedures
:: --4.Triggers
:: --5.RollBack




@ECHO OFF
ECHO CREATE FIRST BACKUP OF ALL DATABASES ON THE DEFAULT INSTANCE ONES:
ECHO CREATING THE LOG FILES

echo THIS IS THE ERROR LOG OF THE UPDATE OF THE DBNAME ON %DATE% >error.log
echo THIS IS THE INSTALL LOG OF THE UPDATE OF THE DBNAME ON %DATE% >install.log


ECHO STARTTING BACKUP
CD .\0.BackUp
ECHO FOR EACH SQL FILE DO RUN IT THIS WILL TAKE A WHILE
ECHO SINCE WE ARE GOING TO MAKE A BACKUP FOR ALL THE DATABASES ON THE CURRENT HOST

for /f %%i in ('dir *.SQL /s /b /o') do ECHO RUNNING %%i1>>"..\install.log"&SQLCMD -U userName -P Password -H hostname -d DBNAME -t 30 -w 80 -u -p 1 -b -i %%i -r1 1>> "..\install.log" 2>> "..\error.log"

ECHO GO ONE FOLDER UP

ECHO SLEEP FOR 1 SECOND
ping -n 1 127.0.0.1 >NUL
ECHO DONE WITH BACKUP GOING UP
cd ..

ECHO THE BACKUPS ARE IN THE FOLDER
ECHO D:\DATA\BACKUPS
ECHO CLICK A KEY TO CONTINUE
ECHO ========================================================================================================================
PAUSE

ECHO START TO EXECUTE THE MIXED FILES
CD .\1.Mixed
ECHO CREATING THE LOG FILES
echo. >>"..\error.log"
echo. >>install.log
ECHO FOR EACH SQL FILE DO RUN IT

for /f %%i in ('dir *.SQL /s /b /o') do ECHO RUNNING %%i1>>"..\install.log"&SQLCMD -U userName -P Password -H hostname -d DBNAME -t 30 -w 80 -u -p 1 -b -i %%i -r1 1>> "..\install.log" 2>> "..\error.log"

ECHO GO ONE FOLDER UP
cd ..

ECHO SLEEP FOR 1 SECOND
ping -n 1 127.0.0.1 >NUL
ECHO DONE WITH MIXED GOING UP

ECHO HIT A KEY AFTER PAUSE
PAUSE
ECHO STARTING INSTALLING TABLES
CD .\2.Tables
ECHO FOR EACH SQL FILE DO RUN IT
ping -n 1 127.0.0.1 >NUL

for /f %%i in ('dir *.SQL /s /b /o') do ECHO RUNNING %%i1>>"..\install.log"&SQLCMD -U userName -P Password -H hostname -d DBNAME -t 30 -w 80 -u -p 1 -b -i "%%i" -r1 1>> "..\install.log" 2>> "..\error.log"


ping -n 1 127.0.0.1 >NUL
ECHO DONE WITH TAbles GOING UP
cd ..
ping -n 1 127.0.0.1 >NUL

ECHO HIT A KEY AFTER PAUSE
PAUSE

ECHO STARTING INSTALLING stored procedures
CD ".\3.StoredProcedures"
ECHO FOR EACH SQL FILE DO RUN IT
ping -n 1 127.0.0.1 >NUL

for /f %%i in ('dir *.SQL /s /b /o') do ECHO RUNNING %%i1>>"..\install.log"&SQLCMD -U userName -P Password -H hostname -d DBNAME -t 30 -w 80 -u -p 1 -b -i "%%i" -r1 1>> "..\install.log" 2>> "..\error.log"

ECHO DONE WITH STORED PROCEDDURES GOING UP
cd ..
ping -n 1 127.0.0.1 >NUL

ECHO HIT A KEY AFTER PAUSE
PAUSE

ECHO STARTING INSTALLING Triggers
CD ".\4.Triggers"
ECHO FOR EACH SQL FILE DO RUN IT
ping -n 1 127.0.0.1 >NUL

for /f %%i in ('dir *.SQL /s /b /o') do ECHO RUNNING %%i1>>"..\install.log"&SQLCMD -U userName -P Password -H hostname -d DBNAME -t 30 -w 80 -u -p 1 -b -i "%%i" -r1 1>> "..\install.log" 2>> "..\error.log"

ping -n 1 127.0.0.1 >NUL
ECHO DONE WITH triggers GOING UP
cd ..

ping -n 1 127.0.0.1 >NUL

ECHO HIT A KEY AFTER PAUSE
PAUSE


ECHO Please , Review the log files and sent them back to Advanced Application Support
cmd /c start /max INSTALL.LOG
CMD /C start /MAX ERROR.LOG
echo DONE !!!
ECHO HIT A KEY TO EXIT
pause
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search