Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««123

Deploying Scripts with SQLCMD Expand / Collapse
Author
Message
Posted Monday, May 11, 2009 5:55 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 11:05 PM
Points: 4, Visits: 32
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.



Post #714645
Posted Monday, August 17, 2009 8:57 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 17, 2014 2:03 PM
Points: 93, Visits: 156
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



Post #771982
Posted Monday, March 8, 2010 11:54 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 18, 2013 3:26 AM
Points: 10, Visits: 37
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.



Post #878827
Posted Wednesday, March 10, 2010 12:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 28, 2011 12:09 PM
Points: 7, 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
Post #879971
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse