i've read a bit about ROWCOUNT but its not exactly what im looking for. from my understanding rowcount states the number of rows affected AFTER you run the query. what im looking for is knowing BEFORE you run the query. is this possible?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
The estimated execution plan is going to give you rows affected based on statistics, so it won't really help you in this case.
What I would recommend is copying your
UPDATE statement
orDELETE statement
and turning it into aSELECT
. Run that to see how many rows come back and you have your answer to how many rows would have been updated or deleted.Eg:
becomes:
Short answer is no..
You cannot get the number of rows before executing the query..atleast in SQL server.
The best way to do it is use
then execute your actual query
You can also use
BEGIN TRANSACTION
before the operation is executed. You can see the number of rows affected. From there, eitherCOMMIT
the results or useROLLBACK
to put the data back in the original state.Review changed data and then:
or
Simplest solution is to replace the columns in the
SELECT * FROM...
withSELECT Count(*) FROM ...
and the rest of your query(theWHERE
clause needs to be the same) before you run it. This will tell you how many rows will be affectedThe simplest solution doesn't seem to work in a case where theres a subquery. How would you select count(*) of this update:
Here I think you need the BEGIN TRANSACTION