MySQL, update multiple tables with one query

前端 未结 6 1664
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 08:00

I have a function that updates three tables, but I use three queries to perform this. I wish to use a more convenient approach for good practice.

How can I update mu

6条回答
  •  鱼传尺愫
    2020-11-22 08:50

    When you say multiple queries do you mean multiple SQL statements as in:

    UPDATE table1 SET a=b WHERE c;
    UPDATE table2 SET a=b WHERE d;
    UPDATE table3 SET a=b WHERE e;
    

    Or multiple query function calls as in:

    mySqlQuery(UPDATE table1 SET a=b WHERE c;)
    mySqlQuery(UPDATE table2 SET a=b WHERE d;)
    mySqlQuery(UPDATE table3 SET a=b WHERE e;)
    

    The former can all be done using a single mySqlQuery call if that is what you wanted to achieve, simply call the mySqlQuery function in the following manner:

    mySqlQuery(UPDATE table1 SET a=b WHERE c; UPDATE table2 SET a=b WHERE d; UPDATE table3 SET a=b WHERE e;)
    

    This will execute all three queries with one mySqlQuery() call.

提交回复
热议问题