douwo5710 2012-04-25 02:40
浏览 40
已采纳

too long

I have 2 MySQL tables having different amount and types of columns. But there's one column of type DATETIME that is called the same in both: expires.

I'm now using 2 queries:

"DELETE FROM `table1` WHERE `expires` < UTC_TIMESTAMP()"
"DELETE FROM `table2` WHERE `expires` < UTC_TIMESTAMP()"

Q1: I have never used the DELETE query for multiple tables that have no connections so I couldn't figure out the right way to create a single query. Is it possible at all without using COMMIT?

Q2: I don't have many records in the DB yet so I can't test the performance difference between using 2 queries from PHP or using a single one to delete the expired records. Does anybody know it?

  • 写回答

2条回答 默认 最新

  • douxuanwei1980 2012-04-25 02:58
    关注

    If you are concerning about time issues for example, the first query will take 1 minute to execute but this will be a problem for your system (the second table values will expire 1 minute + second query execution time later), you might use them together with a transaction like:

    begin transaction
    set @ts = utc_timestamp();
    delete from table_1 where expires< @ts;
    delete from table_2 where expires< @ts;
    commit
    

    and they will be both updated at the same time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计