SQL Server: Is it possible to insert into two tables at the same time?

后端 未结 11 1388
青春惊慌失措
青春惊慌失措 2020-11-22 16:22

My database contains three tables called Object_Table, Data_Table and Link_Table. The link table just contains two columns, the identi

11条回答
  •  眼角桃花
    2020-11-22 16:42

    //if you want to insert the same as first table

    $qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";
    
    $result = @mysql_query($qry);
    
    $qry2 = "INSERT INTO table2 (one,two, three) VVALUES('$one','$two','$three')";
    
    $result = @mysql_query($qry2);
    

    //or if you want to insert certain parts of table one

     $qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";
    
    
      $result = @mysql_query($qry);
    
     $qry2 = "INSERT INTO table2 (two) VALUES('$two')";
    
     $result = @mysql_query($qry2);
    

    //i know it looks too good to be right, but it works and you can keep adding query's just change the

        "$qry"-number and number in @mysql_query($qry"")
    

    I have 17 tables this has worked in.

提交回复
热议问题