Sql update statement, any way of knowing what it actually did?
Typically, I test an update by running a query using the where statement and then after verifying that it does what I think I want it to copying the where clause to the update statement an开发者_开发百科d executing it. But is there any way of getting the statement to return what the update did besides the '4 rows updated'
Sure, take a look at the output clause of T-SQL http://msdn.microsoft.com/en-us/library/ms177564.aspx
You could load your records into a temp table/variable in SQL Server:
DECLARE @Temp TABLE(ID INT)
INSERT INTO @Temp (ID)
SELECT ID
FROM Customer
WHERE AcctBalance > 5000
--inspect as needed
UPDATE Customer
SET AcctBalance = 0
WHERE ID IN (SELECT ID FROM @Temp)
That depend in the server, library that you use, in php, pdo exec return number of row effected by delete or update cluase
精彩评论