Jump to content

SQL Guru required!


OA01

Recommended Posts

I am trying to run a CRON job containing the following commands:

mysql_query("update pireps set rawdata='', log='', route='' where submitdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error());
mysql_query("update adminlog set id='', pilotid='', datestamp='', message='' where datestamp < DATE_SUB(NOW(), INTERVAL 1 MONTH)") or die(mysql_error());
mysql_query("update pirepcomments set id='', pirepid='', pilotid='', comment='', postdate='' where postdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error());

The first two lines appear to run OK. However the last line generates the following error:

Cannot add or update a child row: a foreign key

constraint fails (`orangea1_acars`.`pirepcomments`, CONSTRAINT

`pirepcomments_ibfk_1` FOREIGN KEY (`pirepid`) REFERENCES `pireps` (`pirepid`) ON

DELETE CASCADE ON UPDATE CASCADE)

All suggestions welcomed :)

Link to comment
Share on other sites

Right ok, updating is probably the best bet then, don't do it on any id fields though because they have relationships to other tables (plus emptying a small number from each row saves negligible amounts of space - go for the bulky useless stuff)

Link to comment
Share on other sites

First delete some files such as your fleet files and host them else where and link them to your fleet page. Or you could upgrade your hosting package, to increase the space.
Physical space isn't an issue, I have unlimited. I am just performing good housekeeping! The following works a treat.
mysql_query("update pireps set rawdata='', log='', route='' where submitdate < DATE_SUB(NOW(), INTERVAL 3 MONTH)") or die(mysql_error());
mysql_query("update adminlog set id='', pilotid='', datestamp='', message='' where datestamp < DATE_SUB(NOW(), INTERVAL 1 MONTH)") or die(mysql_error());
mysql_query("DELETE FROM pirepcomments WHERE postdate < DATE_SUB(NOW(), INTERVAL 2 MONTH)") or die(mysql_error());

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...