SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Execute T-SQL Scripts in Parallel

By James Ma, 2009/08/31

Total article views: 2169 | Views in the last 30 days: 463

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.

By James Ma, 2009/08/31

Total article views: 2169 | Views in the last 30 days: 463
Your response
 
 
Related tags

Parallel    
Service Broker    
T-SQL    
 
 
Contribute

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com