Solved

Rowcount

Posted on 2001-06-12
2
2,393 Views
Last Modified: 2010-05-18
I would like to know what Rowcount means.

I'm using the following code as a trigger to always keep the table records as 100,000.

I dont understant the "Set Rowcount 200 " at the begining.
And why do I have to sero it at the end.


CREATE TRIGGER [TRG_CLESR_HISTORY] ON [HISTORY]
FOR  INSERT
AS
while (select count(*) from HISTORY) > 100000
         
BEGIN
     
          SET rowcount 200

          delete HISTORY
          WHERE Date = (SELECT MIN(Date) FROM HISTORY)
         
          SET rowcount 0
     
 END



Thanks !





0
Comment
Question by:kukiya
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6184667
SET ROWCOUNT X
makes that any SELECT  / DELETE / UPDATE statement will only work on the first X rows (given X>0).
If X=0, this restriction is unset.

Let's say you have a table with 100 rows, and you set rowcount 5. SELECT * FROM yourtable will return exactly 5 rows, DELETE Yourtable will delete 5 rows aso.

Your trigger (on the insert statement )does nothing else than delete 200 rows from the HISTORY table as long as there are more than 100000 rows in it, deleting the oldest dates first.

CHeers
0
 

Author Comment

by:kukiya
ID: 6184734
Thaks alot !
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql query 7 36
The duplicate key value is (<NULL>) 14 46
SQL Server issue connecting to named instance 6 43
Syntax using Declare 3 11
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now