pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='FVhgh'><style id='FVhgh'><dir id='FVhgh'><q id='FVhgh'></q></dir></style></legend>

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

  • <small id='FVhgh'></small><noframes id='FVhgh'>

  • <tfoot id='FVhgh'></tfoot>

        <bdo id='FVhgh'></bdo><ul id='FVhgh'></ul>

        “插入忽略"與“插入......在重復的密鑰更新

        quot;INSERT IGNOREquot; vs quot;INSERT ... ON DUPLICATE KEY UPDATEquot;(“插入忽略與“插入......在重復的密鑰更新上)
          <bdo id='89DF9'></bdo><ul id='89DF9'></ul>
            <i id='89DF9'><tr id='89DF9'><dt id='89DF9'><q id='89DF9'><span id='89DF9'><b id='89DF9'><form id='89DF9'><ins id='89DF9'></ins><ul id='89DF9'></ul><sub id='89DF9'></sub></form><legend id='89DF9'></legend><bdo id='89DF9'><pre id='89DF9'><center id='89DF9'></center></pre></bdo></b><th id='89DF9'></th></span></q></dt></tr></i><div class="saaukws" id='89DF9'><tfoot id='89DF9'></tfoot><dl id='89DF9'><fieldset id='89DF9'></fieldset></dl></div>
            <tfoot id='89DF9'></tfoot>

            <small id='89DF9'></small><noframes id='89DF9'>

          • <legend id='89DF9'><style id='89DF9'><dir id='89DF9'><q id='89DF9'></q></dir></style></legend>
                <tbody id='89DF9'></tbody>

                  本文介紹了“插入忽略"與“插入......在重復的密鑰更新上"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在執行包含多行的 INSERT 語句時,我想跳過會導致失敗的重復條目.經過一些研究,我的選擇似乎是使用:

                  While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either:

                  • ON DUPLICATE KEY UPDATE 這意味著需要付出一些代價進行不必要的更新,或者
                  • INSERT IGNORE 暗示邀請其他類型的失敗不經通知就溜進來.
                  • ON DUPLICATE KEY UPDATE which implies an unnecessary update at some cost, or
                  • INSERT IGNORE implies an invitation for other kinds of failure to slip in unannounced.

                  我的這些假設是否正確?簡單地跳過可能導致重復的行并繼續處理其他行的最佳方法是什么?

                  Am I right in these assumptions? What's the best way to simply skip the rows that might cause duplicates and just continue on to the other rows?

                  推薦答案

                  我建議使用 INSERT...ON DUPLICATE KEY UPDATE.

                  如果您使用INSERT IGNORE,那么如果導致重復鍵,該行實際上不會被插入.但該語句不會產生錯誤.相反,它會生成警告.這些情況包括:

                  If you use INSERT IGNORE, then the row won't actually be inserted if it results in a duplicate key. But the statement won't generate an error. It generates a warning instead. These cases include:

                  • 在具有 PRIMARY KEYUNIQUE 約束的列中插入重復鍵.
                  • 將 NULL 插入具有 NOT NULL 約束的列中.
                  • 向分區表插入一行,但您插入的值未映射到分區.
                  • Inserting a duplicate key in columns with PRIMARY KEY or UNIQUE constraints.
                  • Inserting a NULL into a column with a NOT NULL constraint.
                  • Inserting a row to a partitioned table, but the values you insert don't map to a partition.

                  如果你使用REPLACE,MySQL實際上在內部做了一個DELETE后跟一個INSERT,這有一些意想不到的副作用:

                  If you use REPLACE, MySQL actually does a DELETE followed by an INSERT internally, which has some unexpected side effects:

                  • 分配了一個新的自增 ID.
                  • 具有外鍵的相關行可能會被刪除(如果您使用級聯外鍵),否則會阻止 REPLACE.
                  • 不必要地執行在 DELETE 上觸發的觸發器.
                  • 副作用也會傳播到副本.

                  更正:REPLACEINSERT...ON DUPLICATE KEY UPDATE 都是 MySQL 特有的非標準專有發明.ANSI SQL 2003 定義了一個 MERGE 語句,可以解決同樣的(甚至更多)需求,但是 MySQL 不支持 MERGE 語句.

                  correction: both REPLACE and INSERT...ON DUPLICATE KEY UPDATE are non-standard, proprietary inventions specific to MySQL. ANSI SQL 2003 defines a MERGE statement that can solve the same need (and more), but MySQL does not support the MERGE statement.

                  有用戶試圖編輯此帖子(編輯被版主拒絕).該編輯試圖添加一個聲明,即 INSERT...ON DUPLICATE KEY UPDATE 會導致分配一個新的自動遞增 ID.確實,新的id是生成的,但是在改變的行中并沒有使用.

                  A user tried to edit this post (the edit was rejected by moderators). The edit tried to add a claim that INSERT...ON DUPLICATE KEY UPDATE causes a new auto-increment id to be allocated. It's true that the new id is generated, but it is not used in the changed row.

                  請參閱下面的演示,使用 Percona Server 5.5.28 進行測試.配置變量innodb_autoinc_lock_mode=1(默認):

                  See demonstration below, tested with Percona Server 5.5.28. The configuration variable innodb_autoinc_lock_mode=1 (the default):

                  mysql> create table foo (id serial primary key, u int, unique key (u));
                  mysql> insert into foo (u) values (10);
                  mysql> select * from foo;
                  +----+------+
                  | id | u    |
                  +----+------+
                  |  1 |   10 |
                  +----+------+
                  
                  mysql> show create table foo\G
                  CREATE TABLE `foo` (
                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                    `u` int(11) DEFAULT NULL,
                    PRIMARY KEY (`id`),
                    UNIQUE KEY `u` (`u`)
                  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
                  
                  mysql> insert into foo (u) values (10) on duplicate key update u = 20;
                  mysql> select * from foo;
                  +----+------+
                  | id | u    |
                  +----+------+
                  |  1 |   20 |
                  +----+------+
                  
                  mysql> show create table foo\G
                  CREATE TABLE `foo` (
                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                    `u` int(11) DEFAULT NULL,
                    PRIMARY KEY (`id`),
                    UNIQUE KEY `u` (`u`)
                  ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
                  

                  上面演示了IODKU語句檢測到重復,并調用更新來改變u的值.請注意,AUTO_INCREMENT=3 表示生成了 id,但未在行中使用.

                  The above demonstrates that the IODKU statement detects the duplicate, and invokes the update to change the value of u. Note the AUTO_INCREMENT=3 indicates an id was generated, but not used in the row.

                  REPLACE 確實刪除原始行并插入新行,生成存儲一個新的自增 ID:

                  Whereas REPLACE does delete the original row and inserts a new row, generating and storing a new auto-increment id:

                  mysql> select * from foo;
                  +----+------+
                  | id | u    |
                  +----+------+
                  |  1 |   20 |
                  +----+------+
                  mysql> replace into foo (u) values (20);
                  mysql> select * from foo;
                  +----+------+
                  | id | u    |
                  +----+------+
                  |  3 |   20 |
                  +----+------+
                  

                  這篇關于“插入忽略"與“插入......在重復的密鑰更新上"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 數據幀讀取?)

                      • <bdo id='B3srJ'></bdo><ul id='B3srJ'></ul>

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

                            <i id='B3srJ'><tr id='B3srJ'><dt id='B3srJ'><q id='B3srJ'><span id='B3srJ'><b id='B3srJ'><form id='B3srJ'><ins id='B3srJ'></ins><ul id='B3srJ'></ul><sub id='B3srJ'></sub></form><legend id='B3srJ'></legend><bdo id='B3srJ'><pre id='B3srJ'><center id='B3srJ'></center></pre></bdo></b><th id='B3srJ'></th></span></q></dt></tr></i><div class="mask22y" id='B3srJ'><tfoot id='B3srJ'></tfoot><dl id='B3srJ'><fieldset id='B3srJ'></fieldset></dl></div>
                              <tbody id='B3srJ'></tbody>
                            <tfoot id='B3srJ'></tfoot>
                          1. <legend id='B3srJ'><style id='B3srJ'><dir id='B3srJ'><q id='B3srJ'></q></dir></style></legend>
                          2. 主站蜘蛛池模板: 标准件-非标紧固件-不锈钢螺栓-非标不锈钢螺丝-非标螺母厂家-三角牙锁紧自攻-南京宝宇标准件有限公司 | 真丝围巾|真丝丝巾|羊绒围巾|围巾品牌|浙江越缇围巾厂家定制 | 数年网路-免费在线工具您的在线工具箱-shuyear.com | 创富网-B2B网站|供求信息网|b2b平台|专业电子商务网站 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 | 环球电气之家-中国专业电气电子产品行业服务网站! | 春腾云财 - 为企业提供专业财税咨询、代理记账服务 | 南京蜂窝纸箱_南京木托盘_南京纸托盘-南京博恒包装有限公司 | 盘煤仪,盘料仪,盘点仪,堆料测量仪,便携式激光盘煤仪-中科航宇(北京)自动化工程技术有限公司 | 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | COD分析仪|氨氮分析仪|总磷分析仪|总氮分析仪-圣湖Greatlake | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | PCB厂|线路板厂|深圳线路板厂|软硬结合板厂|电路板生产厂家|线路板|深圳电路板厂家|铝基板厂家|深联电路-专业生产PCB研发制造 | 欧必特空气能-商用空气能热水工程,空气能热水器,超低温空气源热泵生产厂家-湖南欧必特空气能公司 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 威廉希尔WilliamHill·足球(中国)体育官方网站 | 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 14米地磅厂家价价格,150吨地磅厂家价格-百科 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 蜜蜂职场文库_职场求职面试实用的范文资料大全 | 鹤壁创新仪器公司-全自动量热仪,定硫仪,煤炭测硫仪,灰熔点测定仪,快速自动测氢仪,工业分析仪,煤质化验仪器 | 逗网红-抖音网红-快手网红-各大平台网红物品导航 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 润东方环保空调,冷风机,厂房车间降温设备-20年深圳环保空调生产厂家 | 智慧养老_居家养老_社区养老_杰佳通| 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 水平垂直燃烧试验仪-灼热丝试验仪-漏电起痕试验仪-针焰试验仪-塑料材料燃烧检测设备-IP防水试验机 | 大学食堂装修设计_公司餐厅效果图_工厂食堂改造_迈普装饰 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 涂层测厚仪_漆膜仪_光学透过率仪_十大创新厂家-果欧电子科技公司 | 电缆隧道在线监测-智慧配电站房-升压站在线监测-江苏久创电气科技有限公司 | 螺杆式冷水机-低温冷水机厂家-冷冻机-风冷式-水冷式冷水机-上海祝松机械有限公司 | 纳米二氧化硅,白炭黑,阴离子乳化剂-臻丽拾科技 | 户外健身路径_小区健身器材_室外健身器材厂家_价格-浩然体育 | WTB5光栅尺-JIE WILL磁栅尺-B60数显表-常州中崴机电科技有限公司 | PE拉伸缠绕膜,拉伸缠绕膜厂家,纳米缠绕膜-山东凯祥包装 | 哈尔滨发电机,黑龙江柴油发电机组-北方星光 | 杭州高温泵_热水泵_高温油泵|昆山奥兰克泵业制造有限公司 | 高压互感器,电流互感器,电压互感器-上海鄂互电气科技有限公司 |