Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

Execute T-SQL Scripts in Parallel

By James Ma,

Transact-SQL does not have a simple method to launch multiple parallel running scripts. The pmaster is a database project that enables you to launch multiple SQL scripts to run in parallel. Just after running a single setup script, you can program your SQL script like the following demo:

use AdventureWorks;

declare @rc int;

-- init before launch sqls
exec @rc = sp_exec_init;

if @rc=0 begin

-- The following sqls will run in parallel
exec sp_exec 'select @@servername waitfor delay ''00:00:10''';
exec sp_exec 'use AdventureWorks
select * from Person.Address
select @@servername waitfor delay ''00:00:10''';
exec sp_exec 'select @@servername waitfor delay ''00:00:10''';
exec sp_exec 'select @@servername waitfor delay ''00:00:10''';

-- Wait until all 'done'.
exec sp_exec_wait;

-- The following sqls will run in parallel
exec sp_exec 'select @@servername waitfor delay ''00:00:10''';
exec sp_exec 'select @@servername waitfor delay ''00:00:10''';

-- Wait until all 'done'.
exec sp_exec_wait;
end

-- end of the session
exec sp_exec_end;

Note: I find the web page's default encoding (Unicode) might change some white space characters in the script, so can cause the script fail to run.

Workaround: First change the page encoding to be "Western European (Windows)", secondly copy and paste the code to a SSMS window, then change the strange character (it's   on my screen) to white space.

Total article views: 9218 | Views in the last 30 days: 60
 
Related Articles
FORUM

Error on this code "GO WAITFOR DELAY '00:00:05'"

The GO and the WAITFOR DELAY execute separately, but not together

FORUM

Using WAITFOR DELAY

I would like to solicit expert opinion about using WAITFOR DELAY and its impact on performance, lock...

FORUM

@@servername and serverproperty('servername') gives different values

select serverproperty('servername') and select @@servername shows different names

FORUM

WAITFOR DELAY - Shortest Delay Possible?

This is baffling me! I have a proc that will call another proc to clear a record (if one exists) ...

FORUM

WAITFOR DELAY causes a lock

Not an issue, but I found this curious. If I run the code: [code="sql"]USE AdventureWorks GO WAI...

Tags
parallel    
service broker    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones