Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to stop an sql query from executing?

I wish to ask if it is possible to stop an sql query during its execution. I wish to do this so that if someone else is executing the same query at the same time, the application would not jam. I am using visual studio c# as front end and oracle 11g as my back end

like image 900
mikespiteri Avatar asked Aug 23 '11 12:08

mikespiteri


People also ask

How do you stop a SQL query from running?

Check the status of the query using the SP_who2 command. After some time, use the KILL command to KILL SPID using the following command. Execute this command in a new query window. Once we execute the KILL SPID command, SQL Server starts the ROLLBACK process for this query.

How do you force stop a SQL query?

SQL Server Management Studio Activity Monitor Scroll down to the SPID of the process you would like to kill. Right click on that line and select 'Kill Process'. A popup window will open for you to confirm that you want to kill the process.

Can you pause a SQL query?

Now pause SQL Server by right clicking on the server instance and selecting Pause. It opens up a pop-up window to confirm or cancel the pause operation. Click Yes to go ahead with the pause operation.


2 Answers

You can wrap the sql query in a pl/sql function and get a lock (with the dbms_lock package) before executing the select statement in the function/procedure (of course you have to release the lock at the end). This way you can serialize the execution of this function.

Another options is to use database jobs.

like image 101
steve Avatar answered Oct 11 '22 00:10

steve


What query are you doing where this is a problem? Most likely that can be optimized to solve whatever issue you're having.

It's not really realistic to do this because for every query that comes in, you'll have to see if someone else is already running it first. That's going to create a lot of overhead and complexity in the system.

like image 25
Tridus Avatar answered Oct 11 '22 00:10

Tridus