Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to know how many rows will be affected before running a query in microsoft sql server 2008

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?

like image 426
user571099 Avatar asked Sep 15 '12 12:09

user571099


People also ask

Which function will return the number of rows affected by a query?

To overcome this issue, SQL Server introduces the ROWCOUNT_BIG system function, which returns the number of rows affected by a specific query in the BIGINT data type.

How can I get the number of records affected by a stored procedure?

In SQL Server, you can use the @@ROWCOUNT system function to return the number of rows affected by the last T-SQL statement. For example, if a query returns 4 rows, @@ROWCOUNT will return 4.

How can I tell how long a SQL query will take?

Using Client StatisticsGo to Menu >> Query >> Select Include client Statistics. Execute your query. In the results panel, you can see a new tab Client Statistics. Go to the Client Statistics tab to see the execution time.


1 Answers

You can also use BEGIN TRANSACTION before the operation is executed. You can see the number of rows affected. From there, either COMMIT the results or use ROLLBACK to put the data back in the original state.

BEGIN TRANSACTION;

UPDATE table
SET col = 'something'
WHERE col2 = 'something else';

Review changed data and then:

COMMIT;

or

ROLLBACK;
like image 192
jabs Avatar answered Sep 19 '22 16:09

jabs