久久久久久久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插入多個表?(數(shù)據(jù)庫規(guī)范化?)

        MySQL Insert into multiple tables? (Database normalization?)(MySQL插入多個表?(數(shù)據(jù)庫規(guī)范化?))
          <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插入多個表?(數(shù)據(jù)庫規(guī)范化?)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我嘗試在同一個查詢的多個表中搜索insert信息,但發(fā)現(xiàn)這是不可能的?所以我想通過簡單地使用多個查詢來 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 命令中插入多個表.但是,您可以使用事務(wù).

                  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.

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

                  讓我詳細(xì)說明:這里有 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.

                  不幸的是,當(dāng)?shù)诙l語句本身在具有自動遞增列的表中插入行時,LAST_INSERT_ID() 將更新為表 2 的,而不是表 1.如果您仍然之后需要表 1 的內(nèi)容,我們將不得不將其存儲在一個變量中.這將我們引向方式 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 變量(或任何語言可以連接到您的數(shù)據(jù)庫選擇):

                • 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 中執(zhí)行該文字語句,或者使用例如 php 的 mysql_insert_id() 為您執(zhí)行此操作
                  • 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]

                  警告

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

                  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.

                  但是,如果您決定要么完成所有查詢,要么不完成 - 我不希望某些表中的行但其他表中沒有匹配的行,我總是希望我的數(shù)據(jù)庫表保持一致",您需要包裝所有交易中的語句.這就是我在這里使用 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.

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

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

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項是忽略整個事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環(huán)數(shù)組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時發(fā)生錯誤 沒有合適的驅(qū)動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)
                    <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>
                          • 主站蜘蛛池模板: 日韩久久精品 | 我爱操 | 久久成人一区 | 在线观看特色大片免费网站 | 亚洲精品www | 精品国产欧美一区二区三区成人 | 在线第一页| 亚洲伊人久久综合 | 日韩成人免费视频 | 狠狠干狠狠操 | 日韩一二三区视频 | 欧美一区二区在线播放 | 亚洲免费成人av | 青青久久| 国产欧美在线一区 | 综合激情久久 | 中文日本在线 | 欧美精品二区 | 欧美一区二区三区在线视频 | 黄色毛片大全 | 成人在线免费 | 国产精品国产三级国产aⅴ入口 | 国产精品99久久久久久人 | 成人黄色av | 亚洲精品久久久久久久不卡四虎 | 久久久久网站 | 在线观看亚洲专区 | 波多野吉衣在线播放 | 嫩呦国产一区二区三区av | 欧美精品一区在线 | 国产精品久久久久久久久污网站 | 日本天天操 | 久草资源| av三级| 一二三区视频 | 亚洲精品久久久一区二区三区 | 久久国产区| 99视频在线 | 日韩免费一区 | re久久| 欧美视频一级 |