mySQL插入到多個表
使用Transactions和last_insert_id() 插入用戶(用戶名,密碼)值('test','test'); 插入配置文件(userId,by,homepage)值(last_insert_id(),'Hello world!','http://www.stackoverflow.com'); commit; 以“ begin;”。 插入第一個表格,使用“ last_insert_id()”。 “ commit;”。
在變量
,將自動啟動ID存儲在變量中允許在後續查詢中引用其引用。這可以使用:插入... 將last_insert_id()選擇為@mysql_variable_here; 插入到table2(@mysql_variable_here,...);
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3