Link to home
Start Free TrialLog in
Avatar of TPoly
TPoly

asked on

Perl to delete data automatically

hi...
may i know how to delete data from db automatically using perl?
btw i want to be able to delete files that's a year old
eg. year 2000 data to be programmed to be deleted at the beginning of year 2002

the date in the date table is written as 12/3/00

thanks


SOLUTION
Avatar of suramsureshbabu
suramsureshbabu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TPoly
TPoly

ASKER

eh win32?
sorry i forgot ot add that i'm not using window
i'm using debian linux 3.0 and perl 5.6.1
Avatar of Dave Cross
That's pretty simple. Use DBI to connect to the database and run an SQL query to delete data that is too old. Set the program to run periodically using cron.

Dave...
Avatar of TPoly

ASKER

so how to write the program to run periodically?
I do know how to use cron
btw what type of program are you refering to? perl is it?

btw i'm using mysql as my db
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TPoly

ASKER

hi..
 the script u have provide is unable to work...

is it possible that my sql statment is not workable

delete from table where YEAR(12/3/00) = YEAR(CURRENT_DATE())-2;

thanks

Yes, it's quite likely that your SQL is incorrect. I very much doubt that you have a table called "table". And what is the date column called?
Avatar of TPoly

ASKER

ok
the sql statement i've put in this:
delete from yield where YEAR(12/3/00)=YEAR(CURRENT_DATE())-2;

Date column is called "date"
Yes, I know that's the SQL statement you used - you put it in your last post too :)

You should probably be asking this in an SQL forum, but I expect you need something like

delete from yield where year(date) <= year(current_date()) - 2

Obviously, you should test that in a transaction first so you can roll it back if there's a problem.

Dave...
Avatar of TPoly

ASKER

i've tried this statment and it is able to execute but unable to delete any date in
the date column.
Try experimenting with select statements until you find one that returns the list of rows that you need to delete. Then it's simple to convert it into a delete statement.

But like I said before, this is no longer a Perl question and you should be asking it in an SQL forum.

Dave...