Friday, February 24, 2012

For implementing wrap around for a table

Hi,
Iam looking a good solution for wrapping around records in the table. The
requirement is to keep only last n (eg. 20000) number of records in the
table.
After inserting the n+1 record the first record need to be removed from the
table. so on...
Is it better to place the logic in the application side or in the database
server side (using stored procedure /triggeres')?
HariUsually something like this is done in a scheduled job. I can't believe
the number has to be exactly 20000 so a job that runs every so often can
trim the old rows. You typically don't want to burden the app or the
transaction with cleanup type work.
Andrew J. Kelly SQL MVP
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:AA2E781B-31E9-4754-843C-7F1C1A939846@.microsoft.com...
> Hi,
> Iam looking a good solution for wrapping around records in the table. The
> requirement is to keep only last n (eg. 20000) number of records in the
> table.
> After inserting the n+1 record the first record need to be removed from
> the
> table. so on...
> Is it better to place the logic in the application side or in the database
> server side (using stored procedure /triggeres')?
> Hari
>|||What do you want to do with record #1 when record #20001 is added to the
table? Delete it, move it somewhere else? Is there a possibility this
could muck up relationships to other tables when these records are removed?
"Hari" <Hari@.discussions.microsoft.com> wrote in message
news:AA2E781B-31E9-4754-843C-7F1C1A939846@.microsoft.com...
> Hi,
> Iam looking a good solution for wrapping around records in the table. The
> requirement is to keep only last n (eg. 20000) number of records in the
> table.
> After inserting the n+1 record the first record need to be removed from
> the
> table. so on...
> Is it better to place the logic in the application side or in the database
> server side (using stored procedure /triggeres')?
> Hari
>|||Rows and records are totally different concepts; you need to learn the
difference if you are going to write SQL. Please post DDL, so that
people do not have to guess what the keys, constraints, Declarative
Referential Integrity, datatypes, etc. in your schema are. Sample data
is also a good idea, along with clear specifications.
Having said that, I would go with a trigger on the database side.
Ugly, but safer than depending on application to enforce the rules.

No comments:

Post a Comment