[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Rowcount

Posted on 2001-06-12
2
Medium Priority
?
2,468 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

873 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