且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL-如何使用外键插入多个表

更新时间:2023-01-29 08:55:33

您最有可能必须按照相关性顺序插入内容.因此,如果您有三个表(A,B和C),我们假设C依赖于B,B依赖于A.我们还假设每个表分别具有主键AID,BID和CID.

You're most likely going to have to insert things in order of their dependence. So if you have three tables (A, B, and C) we'll assume C depends on B and B depends on A. We'll also assume each table has primary keys AID, BID, and CID respectively.

  1. 您需要将行插入A并获得AID.
  2. 然后,您将使用从步骤1获得的AID将行插入到B中.
  3. 然后,您将使用从第2步(也许是1)中获得的BID(也许是AID)将行插入C中