Solved

Rowcount

Posted on 2001-06-12
2
2,405 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

910 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

24 Experts available now in Live!

Get 1:1 Help Now