By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

counting the inserts and updates on a table in a sql server database

P: n/a
Hello,

Can someone point me to getting the total number of inserts and updates on a table
over a period of time?

I just want to measure the insert and update activity on the tables.

Thanks.

- Vish
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On a single statement you can capture the @@rowcount into a variable and
write it to a log table. But if I'm reading this correctly, you don't want
to do this through the existing code base. Inserts are usually easy if
there is a primary or unique key. Assuming no deletes, simply how many new
keys are there since the last count. Or if the key is incrementing by one
what's the max value - the previous max value. Updates are more vague. How
many rows were updated or how many updates occurred These activities are
usually accommodated for in the initial table design with flag and
last_mod_date columns. Without auditing written into every piece of code or
proper schema design it's an ugly intensive task to rub to data sets
together (using checksums or straight comparisons) to find differences.

Danny

"Viswanatha Thalakola" <vt********@yahoo.com> wrote in message
news:d7**************************@posting.google.c om...
Hello,

Can someone point me to getting the total number of inserts and updates on
a table
over a period of time?

I just want to measure the insert and update activity on the tables.

Thanks.

- Vish

Jul 20 '05 #2

P: n/a
On 30 Nov 2004 18:45:55 -0800, Viswanatha Thalakola wrote:
Hello,

Can someone point me to getting the total number of inserts and updates on a table
over a period of time?

I just want to measure the insert and update activity on the tables.

Thanks.

- Vish


Hi Vish,

The easiest way to do this is to add some counting logic to the stored
procedures that do the inserting, updating and deleting. But if you can't
or won't change those tables (or if you allow direct data modifications,
without using stored procedures), you have two other options:

1. Set up a profiler trace. Catch the trace results in a table or in a
file, then use either SQL queries (if in a table) or text manipulation
tools (if in a file) to count the number of inserts, updates, etc. I must
add that I don't know the exact format and I'm not sure either if the
number of rows affected is included in the trace data (it it isn't, you
can't use this approach).

2. Create triggers for each table you need to monitor. Have these triggers
copy @@rowcount in a local variable as the first statement (that yields
the number of rows affected by the statement that fired the trigger) and
save that value to a table.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #3

P: n/a
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
1. Set up a profiler trace. Catch the trace results in a table or in a
file, then use either SQL queries (if in a table) or text manipulation
tools (if in a file) to count the number of inserts, updates, etc. I must
add that I don't know the exact format and I'm not sure either if the
number of rows affected is included in the trace data (it it isn't, you
can't use this approach).


It isn't, but you can catch number of page writes. Still, though, not a
wholly reliable number.

Then again, I assume that the aim is not to save exact numbers, but get
some approxamite statistics, so some Profiler method is proably better
than adding triggers to the system.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.