473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to automate deletion of oldest rows when table reaches certain number of rows?

Is there a way to automate the deletion of the oldest rows in a transaction log file when the file reaches a certain number of rows? Currently, we are simply deleting the oldest rows manually every so often. But we would like to put something in place that will do this automatically. The reason for doing this is to ultimately improve the application's performance that writes the transactions to this file. When the file gets to be over about 60,000 rows, performance of the application seems to degrade.
Jan 5 '07 #1
12 2828
iburyak
1,017 Expert 512MB
Do you have unique ID in this table?
Jan 5 '07 #2
Yes, there is a unique RecordID
Jan 5 '07 #3
iburyak
1,017 Expert 512MB
1. Create test environment

[PHP]select * into #temp_table from log_table [/PHP]

2. [PHP]Select * from #temp_table where ID not in (Select Top 60000 ID from #temp_table order by ID desc) [/PHP]
-- you can use date or other order criteria make sure it is desc. The idea is to select last 60000 records and exclude them from delete
-- Check if these are the records you want to delete.
3. [PHP]Delete from #temp_table where ID not in (Select Top 60000 ID from #temp_table order by ID desc)[/PHP]
4. Move everything in production if it worked to your satisfaction.


Godd Luck.
Jan 5 '07 #4
Thank you, iburyak. I am truly a novice at SQL. What do I need to do next in order to get this to then delete the records from the original table, and automate this?
Jan 5 '07 #5
iburyak
1,017 Expert 512MB
Did you test delete? Did it work as you expected?
Jan 5 '07 #6
I just tested the selects you sent, and yes, they did work. But I don't know how to then delete the records?
Jan 5 '07 #7
iburyak
1,017 Expert 512MB
How often do you need to do it?
Jan 5 '07 #8
iburyak
1,017 Expert 512MB
Do you have access to SQL Server Enterprize Manager?
Can you see your Server name there?
Jan 5 '07 #9
Yes, I can get to Ent Mgr. I believe this should be done daily.
Jan 5 '07 #10
iburyak
1,017 Expert 512MB
Go to Ent Manager.
Open your server.
Go to Management - SQL Server Agent - Jobs
Right click on Jobs and select New Job....

Give it any name you want like PurgeLog
go to Steps and click New. Put delete statement there.
go to Schedules click New Schedule, give it a name and click Change.
Select how often you want to do it and save everything.

Now you all set. You will see your job name, you can right click on it and start right away or wait for scheduled time and View Job history when you want to check if job is running every time successfully.

Good luck.
Jan 5 '07 #11
GREAT!!! Thanks so much for your help!!!!
Jan 5 '07 #12
iburyak
1,017 Expert 512MB
You are welcome.... :)
Jan 5 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
0
by: Marco | last post by:
Hi to all I have a question about deletion of amount of data: My production environment is this one: - one publisher with a database (historycal events) - 50 subscribers with the prev...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.