Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop
I have 4 scripts to run in SQL 2008 R2, easy enough, run each one after each other.
The question is, is it possible to run all 4 scripts together in one window but pausing to execute after each one?
Obviousley this may be science fiction, but it seems tottally plausable in my mind
when you say four scripts, are you writing them in SSMS and then running them? or are you importing files?
What i discovered this week was that if i write multiple scripts in one SQL file it works.
Not really familiar with SQL 2008, but generally you would just follow each script with a semi-colon; and each would be executed in sequence.
we're writing scripts to set up databases in SQL for sofware we use, 4 databases, but one needs to execute before the next, but we would like it to be one long script rather than 4 scripts to be executed one after the other
so:
run script one > execute > run script two > execute and so on
This any good ?
http://www.mssqltips.com/sqlservertip/1543/using-sqlcmd-to-execute-multiple-sql-server-scripts/
as a newby with limited experience i would do the following.
cut and paste each of the four scripts into one file, do it in the order you need the databases to run, and then execute.
Did something similar last week creating some views.
I don't see why you couldn't just stick them in the same file sequentially in the order that you want them to run, just whack "GO" between each script and it should definitely work... That's how we script out creating tables etc... where objects later in the script depend on ones earlier.
when you say four scripts, are you writing them in SSMS and then running them? or are you importing files?
Yes
I don't see why you couldn't just stick them in the same file sequentially in the order that you want them to run, just whack "GO" between each script and it should definitely work... That's how we script out creating tables etc... where objects later in the script depend on ones earlier.
Thats what I thought, but aparantley I'm too thick to know this myself so I've been tasked to find out, so I'm taking the cheating method and asking the hive mind.......office politics, don't you love it
I'm fairly sure that should work, if you're in doubt then can you test in a sandbox or something?
yes that will work. e.g.
select * from table1
go
select * from table2
go
select * from table3
go
select * from table4
go
or even change dbs, e.g.
use Database1
go
select * from table1
go
use Database2
go
select * from table2
go
use Database3
go
select * from table3
go
use Database4
go
select * from table4
go
if in doubt, stick a transaction round it, at the end check for errors and rollback if you find any, else commit
