0

I have a PHP/MySQL project having 15 tables. One of table name tbl_user_log, where all user log will saved. I want to empty or truncate this table in every 3 month.How could I do this using trigger or any solution is applicable.

Daniel Smith
  • 1,626
  • 3
  • 29
  • 59
  • 2
    possible duplicate of [Automatic TRUNCATE table in MySQL](http://stackoverflow.com/questions/21956291/automatic-truncate-table-in-mysql) – Martin Apr 03 '15 at 05:31

2 Answers2

0

You can set a cronjob to a certain route of your project to perform following sql:

DELETE FROM tbl_user_log

See this website: http://setcronjob.com

Or you can simply use mysql EVENTs.

Hamid Mohayeji
  • 3,977
  • 3
  • 43
  • 55
0

It may helps you

declare @tbl nvarchar(max)='table_name'
if (
       (select create_date FROM
        sys.tables where name=@tbl)
        <=  (SELECT DATEADD(month,-3, GETDATE()))
begin
truncate table @tbl
end
else
select 'table creation date is not more than 3 months'

better you can put this in a procedure and u can directly pass table name as input and can wrk efficently

koushik veldanda
  • 1,079
  • 10
  • 23