Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Prompt in Query Analyser

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-02-05 : 10:41:35
Is there antway I can get the Query Analyser to prompt me with a message saying '234 records will be updated' and then give me the option to continue or not.

I want to run an update query but want to see how many records it will update first.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-05 : 10:45:56
Highlight the Update statement by selecting it and press Ctrl + L. In the estimated execution plan, check the final Estimated Row count value.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-02-05 : 10:51:56
Thanks.
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2007-02-05 : 10:58:43
Or u may use

begin tran
Update ..........

-- If OK
commit
-- If not OK
rollback


Srinika
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-02-08 : 06:50:10
I get this error
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

begin trans
Update RD
set Dept = R.Dept
from tblFileRequestDetailsCopy as RD
JOIN tblFileRequests as R
on RD.MovementId = R.MovementId
where RD.dept is null

-- If OK
commit
-- If not OK
rollback
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-08 : 07:01:41
Don't just copy replies posted here. Try to understand the logic behind them.

What Srinika meant was:

Begin Transaction

Update RD
set Dept = R.Dept
from tblFileRequestDetailsCopy as RD
JOIN tblFileRequests as R
on RD.MovementId = R.MovementId
where RD.dept is null

If @@error = 0 -- OK
Commit Transaction
Else -- not OK
Rollback Transaction


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-02-08 : 10:32:25
Don't just copy replies posted here. Try to understand the logic behind them.

This forum is called New to SQL Server. I am self taught off the web and do look up the keywords etc that I am given here. I also have a library of code that has helped me that kind people have given me on sites such as these. Hopefully, one day I will be as well knowledged in SQL as you Harsh Athalye and will be able to help others.

I do not look for the easy, lazy way to code by pinching others code or getting others to write it for me. Often, I have searched for hours for the solution before posting here. Sometimes though, you need to know part of the solution to be able to find it all.

You have helped me often Harsh Athalye and I have before, and do thank you for that.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-09 : 02:59:01
I know it is difficult for newbies to understand seemingly complex code. But if you could have done some search firstly in the SQL Server help files regarding transactions and corresponding examples, you could have easily spotted your mistake. You will only learn when you try to find out the solution on your own.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -