久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='054Wk'><style id='054Wk'><dir id='054Wk'><q id='054Wk'></q></dir></style></legend>
    <i id='054Wk'><tr id='054Wk'><dt id='054Wk'><q id='054Wk'><span id='054Wk'><b id='054Wk'><form id='054Wk'><ins id='054Wk'></ins><ul id='054Wk'></ul><sub id='054Wk'></sub></form><legend id='054Wk'></legend><bdo id='054Wk'><pre id='054Wk'><center id='054Wk'></center></pre></bdo></b><th id='054Wk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='054Wk'><tfoot id='054Wk'></tfoot><dl id='054Wk'><fieldset id='054Wk'></fieldset></dl></div>

    <small id='054Wk'></small><noframes id='054Wk'>

      • <bdo id='054Wk'></bdo><ul id='054Wk'></ul>

      1. <tfoot id='054Wk'></tfoot>

        MySQL插入多個表?(數據庫規范化?)

        MySQL Insert into multiple tables? (Database normalization?)(MySQL插入多個表?(數據庫規范化?))
          <tbody id='Jn5PK'></tbody>

        <small id='Jn5PK'></small><noframes id='Jn5PK'>

        <i id='Jn5PK'><tr id='Jn5PK'><dt id='Jn5PK'><q id='Jn5PK'><span id='Jn5PK'><b id='Jn5PK'><form id='Jn5PK'><ins id='Jn5PK'></ins><ul id='Jn5PK'></ul><sub id='Jn5PK'></sub></form><legend id='Jn5PK'></legend><bdo id='Jn5PK'><pre id='Jn5PK'><center id='Jn5PK'></center></pre></bdo></b><th id='Jn5PK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Jn5PK'><tfoot id='Jn5PK'></tfoot><dl id='Jn5PK'><fieldset id='Jn5PK'></fieldset></dl></div>
        • <legend id='Jn5PK'><style id='Jn5PK'><dir id='Jn5PK'><q id='Jn5PK'></q></dir></style></legend>

                • <bdo id='Jn5PK'></bdo><ul id='Jn5PK'></ul>
                  <tfoot id='Jn5PK'></tfoot>

                  本文介紹了MySQL插入多個表?(數據庫規范化?)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我嘗試在同一個查詢的多個表中搜索insert信息,但發現這是不可能的?所以我想通過簡單地使用多個查詢來 insert 它,即;

                  I tried searching a way to insert information in multiple tables in the same query, but found out it's impossible? So I want to insert it by simply using multiple queries i.e;

                  INSERT INTO users (username, password) VALUES('test', 'test')
                  INSERT INTO profiles (userid, bio, homepage) VALUES('[id of the user here?]','Hello world!', 'http://www.stackoverflow.com')
                  

                  但是如何將 users 的自動增量 id 提供給 profile<的手動"userid/code> 表?

                  But how can I give the auto-increment id from the users to the "manual" userid for the profile table?

                  推薦答案

                  不,您不能在一個 MySQL 命令中插入多個表.但是,您可以使用事務.

                  No, you can't insert into multiple tables in one MySQL command. You can however use transactions.

                  BEGIN;
                  INSERT INTO users (username, password)
                    VALUES('test', 'test');
                  INSERT INTO profiles (userid, bio, homepage) 
                    VALUES(LAST_INSERT_ID(),'Hello world!', 'http://www.stackoverflow.com');
                  COMMIT;
                  

                  看看LAST_INSERT_ID() 重用自增值.

                  Have a look at LAST_INSERT_ID() to reuse autoincrement values.

                  你說經過這么長時間的嘗試,它仍然不起作用.我不能簡單地將剛剛生成的 ID 放在 $var 中并將該 $var 放在所有 MySQL 命令中嗎?"

                  讓我詳細說明:這里有 3 種可能的方法:

                  Let me elaborate: there are 3 possible ways here:

                  1. 在上面的代碼中.這個這一切都在 MySQL 中完成,并且LAST_INSERT_ID() 在第二個語句將自動成為自動增量列的值插入第一個聲明.

                  1. In the code you see above. This does it all in MySQL, and the LAST_INSERT_ID() in the second statement will automatically be the value of the autoincrement-column that was inserted in the first statement.

                  不幸的是,當第二條語句本身在具有自動遞增列的表中插入行時,LAST_INSERT_ID() 將更新為表 2 的,而不是表 1.如果您仍然之后需要表 1 的內容,我們將不得不將其存儲在一個變量中.這將我們引向方式 2 和方式 3:

                  Unfortunately, when the second statement itself inserts rows in a table with an auto-increment column, the LAST_INSERT_ID() will be updated to that of table 2, and not table 1. If you still need that of table 1 afterwards, we will have to store it in a variable. This leads us to ways 2 and 3:

                  將把 LAST_INSERT_ID() 存入一個 MySQL 變量:

                  Will stock the LAST_INSERT_ID() in a MySQL variable:

                  INSERT ...
                  SELECT LAST_INSERT_ID() INTO @mysql_variable_here;
                  INSERT INTO table2 (@mysql_variable_here, ...);
                  INSERT INTO table3 (@mysql_variable_here, ...);
                  

                • 將把 LAST_INSERT_ID() 存入一個php 變量(或任何語言可以連接到您的數據庫選擇):

                • Will stock the LAST_INSERT_ID() in a php variable (or any language that can connect to a database, of your choice):

                  • 插入...
                  • 使用您的語言來檢索LAST_INSERT_ID(),方法是在 MySQL 中執行該文字語句,或者使用例如 php 的 mysql_insert_id() 為您執行此操作
                  • INSERT [在此處使用您的 php 變量]
                  • INSERT ...
                  • Use your language to retrieve the LAST_INSERT_ID(), either by executing that literal statement in MySQL, or using for example php's mysql_insert_id() which does that for you
                  • INSERT [use your php variable here]

                  警告

                  無論您選擇哪種解決方法,您都必須決定應該發生什么執行在查詢之間中斷(例如,您的數據庫服務器崩潰).如果您可以忍受有些已經完成,有些還沒有",請不要繼續閱讀.

                  WARNING

                  Whatever way of solving this you choose, you must decide what should happen should the execution be interrupted between queries (for example, your database-server crashes). If you can live with "some have finished, others not", don't read on.

                  但是,如果您決定要么完成所有查詢,要么不完成 - 我不希望某些表中的行但其他表中沒有匹配的行,我總是希望我的數據庫表保持一致",您需要包裝所有交易中的語句.這就是我在這里使用 BEGINCOMMIT 的原因.

                  If however, you decide "either all queries finish, or none finish - I do not want rows in some tables but no matching rows in others, I always want my database tables to be consistent", you need to wrap all statements in a transaction. That's why I used the BEGIN and COMMIT here.

                  這篇關于MySQL插入多個表?(數據庫規范化?)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
                • 相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                    <tbody id='NIJLS'></tbody>

                  1. <small id='NIJLS'></small><noframes id='NIJLS'>

                      • <legend id='NIJLS'><style id='NIJLS'><dir id='NIJLS'><q id='NIJLS'></q></dir></style></legend>
                        <i id='NIJLS'><tr id='NIJLS'><dt id='NIJLS'><q id='NIJLS'><span id='NIJLS'><b id='NIJLS'><form id='NIJLS'><ins id='NIJLS'></ins><ul id='NIJLS'></ul><sub id='NIJLS'></sub></form><legend id='NIJLS'></legend><bdo id='NIJLS'><pre id='NIJLS'><center id='NIJLS'></center></pre></bdo></b><th id='NIJLS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NIJLS'><tfoot id='NIJLS'></tfoot><dl id='NIJLS'><fieldset id='NIJLS'></fieldset></dl></div>

                        <tfoot id='NIJLS'></tfoot>
                          <bdo id='NIJLS'></bdo><ul id='NIJLS'></ul>
                          • 主站蜘蛛池模板: 亚洲视频在线观看 | 免费在线黄色网址 | 91欧美大片 | 午夜久久久久久 | 国产午夜精品一区二区三区视频 | 久久久久久黄色 | 99视频免费观看 | 日韩精品久久久 | 刘玥大战28公分黑人 | 免费一区二区三区 | 久热国产视频 | 九九在线精品 | 国产999视频 | 国产午夜在线 | 99色综合 | 欧美xxxx网站 | 午夜网站在线观看 | 亚洲一区av | 国产成人a亚洲精品 | 精品www | 日韩精品久久 | 日韩精品毛片 | 国产一级大片 | 国产视频中文字幕 | 日韩在线欧美 | 免费爱爱网站 | www.九色| 国产三级在线播放 | 91午夜精品亚洲一区二区三区 | 日本国产精品 | 日本一级淫片色费放 | 久久久免费观看 | 天天摸夜夜操 | 国产精品久久久久久妇女6080 | 欧美日韩综合网 | 69免费视频 | 九九在线精品 | 日韩精品视频在线播放 | 黑人精品xxx一区一二区 | 久久久久久黄色 | 成年人免费在线视频 |