Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts 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: 9867 | Views in the last 30 days: 6
 
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

TRUNCATE with WAITFOR DELAY

Greetings, I've recently inherited a slew of databases and many of the table population stored pr...

Tags
parallel    
service broker    
t-sql    
 
Contribute