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 Administration
 Question about an update

Author  Topic 

V.V.
Starting Member

32 Posts

Posted - 2010-12-22 : 13:22:48
Guys, I want to ask you something regarding an update. I queried one table in order to return me a specific row:

SELECT * FROM X
WHERE IDCLIENT='1234567890' AND CLIENTSERIES='0048'

Ok. I wanted to update a status of this client from a to b.

SELECT * FROM X
UPDATE X
SET STATUS=B
WHERE IDCLIENT='1234567890' AND CLIENTSERIES='0048'

The problem is that I forgot to comment the line with 'SELECT' and I selected with mouse this line too when I pressed F5. When i realized what have I done I stopped the operation. My question is if my table was somehow affected because I forgot to comment that line.

In the result and also messages window nothing appeared like 'X row(s) affected' just 'Query was cancelled by user'.



tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-22 : 13:26:06
It was fine that the select was included in the batch. It would have meant that it would display the table and then run your update. The fact that you cancelled it before the update completed means it was rolled back, so you are good in all aspects.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

V.V.
Starting Member

32 Posts

Posted - 2010-12-22 : 13:31:32
Ok, sorry for my bad english but in other words, the first operation in the query executed was the SELECT one and the UPDATE operation was the final one, right?

Ok, so nothing have been changed. That's good.

But what happens in case the operation is not cancelled? It updates me just that record because I mentioned the WHERE clause or something else also?

Thanks very much.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-22 : 13:44:17
If that entire batch was higlighted and you let it complete, then it would have displayed your table due to the select and then updated that one row.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

V.V.
Starting Member

32 Posts

Posted - 2010-12-22 : 13:50:49
Thank you tkizer.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-12-22 : 14:04:43
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -