Posts
820
Comments
681
Trackbacks
1
<< General SQL FAQ Word Doc | Home | Tips on reducing shopping cart abandonment >>
How to kill a long running t-sql query

This only applies to certain cases, of course.

Through 'user error,' I managed to launch a sql script (at the end of the day, natually) that was still running the next day when I came in.  Because it was a script that populated a table, I knew if I tried to cancel/kill the process, it would then attempt to roll it back, which would take forever and a day.

Luckily, my script used sub-queries in it.  In cases such as this, all you have to do is to add data somewhere/anywhere that the sub-query is looking at, so that the sub-query pulls back more than one row.  Tada, script errors out.

posted on Tuesday, March 08, 2005 8:55 AM
Comments
Gravatar
# re: How to kill a long running t-sql query
6/28/2011 4:15 PM
$result = mysql_query("SHOW FULL PROCESSLIST");
while ($row=mysql_fetch_array($result)) {
$process_id=$row["Id"];
if ($row["Time"] > 200 ) {
$sql="KILL $process_id";
mysql_query($sql);
}
}

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 7 and 8 and type the answer here: