Solved

Rowcount

Posted on 2001-06-12
2
2,442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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)

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

737 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