0

This is the query I tried running. I was testing out a ROLLBACK because we need to do it in an assignment.

BEGIN TRANSACTION;

declare @var bit;
set @var = 0;

BEGIN TRY
    INSERT INTO Orders(ShippingAddress, BillingAddress, Status, Date, ID, CustomerID, Total, BillingInfo) 
    VALUES('10 King Road', '10 King Road', 'Pending', '2013-03-15 07:58:55.760', 16, 1, 145.95, 'Put it on my doorstep please.');
END TRY
BEGIN CATCH
    IF @var > 0
    ROLLBACK TRANSACTION;
END CATCH;

IF @var > 0
    COMMIT TRANSACTION;

After I ran it successfully, I tried to do a SELECT * FROM Orders and now SQL Server just tries to run the ExecuteQuery forever... my partner also has the same trouble but all of our other tables work fine. Anybody have any idea what may be the cause of this? I'm using Microsoft SQL Server 2012. Thanks

1 Answer 1

1

What is @var, and when it will be > 0. if the @var didn't changed to 1 Started TRANSACTION never COMMIT or ROLLBACK. So the table will be locked till the TRANSACTION ends.

3
  • how do you end the transaction?
    – aug
    Mar 16, 2013 at 5:07
  • If the table is locked. you can check the table locks and KILL the process Using KILL. to run the query correctly just remove the line IF @var > 0
    – SAM
    Mar 16, 2013 at 5:26
  • I couldn't use the KILL command because I didn't have access (I'm not the owner of the server) but I think the transaction timed out and queries are working fine again. Thank you so much. I'll never do that again -_-.
    – aug
    Mar 16, 2013 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.