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

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

      <i id='HU5HA'><tr id='HU5HA'><dt id='HU5HA'><q id='HU5HA'><span id='HU5HA'><b id='HU5HA'><form id='HU5HA'><ins id='HU5HA'></ins><ul id='HU5HA'></ul><sub id='HU5HA'></sub></form><legend id='HU5HA'></legend><bdo id='HU5HA'><pre id='HU5HA'><center id='HU5HA'></center></pre></bdo></b><th id='HU5HA'></th></span></q></dt></tr></i><div id='HU5HA'><tfoot id='HU5HA'></tfoot><dl id='HU5HA'><fieldset id='HU5HA'></fieldset></dl></div>
      1. <legend id='HU5HA'><style id='HU5HA'><dir id='HU5HA'><q id='HU5HA'></q></dir></style></legend>

        <tfoot id='HU5HA'></tfoot>

        如何强制 MySQL 将 0 作为有效的自动递增值

        How to force MySQL to take 0 as a valid auto-increment value(如何强制 MySQL 将 0 作为有效的自动递增值)
        • <legend id='3hIXL'><style id='3hIXL'><dir id='3hIXL'><q id='3hIXL'></q></dir></style></legend>

            <small id='3hIXL'></small><noframes id='3hIXL'>

          1. <i id='3hIXL'><tr id='3hIXL'><dt id='3hIXL'><q id='3hIXL'><span id='3hIXL'><b id='3hIXL'><form id='3hIXL'><ins id='3hIXL'></ins><ul id='3hIXL'></ul><sub id='3hIXL'></sub></form><legend id='3hIXL'></legend><bdo id='3hIXL'><pre id='3hIXL'><center id='3hIXL'></center></pre></bdo></b><th id='3hIXL'></th></span></q></dt></tr></i><div id='3hIXL'><tfoot id='3hIXL'></tfoot><dl id='3hIXL'><fieldset id='3hIXL'></fieldset></dl></div>

              • <bdo id='3hIXL'></bdo><ul id='3hIXL'></ul>
                    <tbody id='3hIXL'></tbody>
                  <tfoot id='3hIXL'></tfoot>

                  本文介绍了如何强制 MySQL 将 0 作为有效的自动递增值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  长话短说,我有一个 SQL 文件,我想将其导入为 skel 样式文件,因此这将以编程方式重复执行.我可以随意编辑 SQL 文件,但我不想接触应用程序本身.

                  Long story short, I have a SQL file that I want to import as a skel style file, so this will be done repeatedly, programmatically. I can edit the SQL file however I want, but I'd rather not touch the application itself.

                  此应用程序使用 userid = 0 来表示匿名用户.它还在数据库中有一个相关的(空白)条目来表示这个用户".因此,我的 skel.sql 中的行看起来像这样:

                  This application uses userid = 0 to represent the anonymous user. It also has a relevant (blank) entry in the database to represent this 'user'. Hence, the line in my skel.sql looks something like this:

                  INSERT INTO `{{TABLE_PREFIX}}users` VALUES (0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, 0, NULL, '', '', '', NULL);
                  

                  问题在于 uid 是一个 auto_increment 字段,从技术上讲,0 是一个无效值.或者至少,如果你将它设置为 0,你基本上是在告诉 MySQL,请在这个字段中插入下一个 id."

                  The problem with this is that uid is a auto_increment field, for which, technically, 0 is an invalid value. Or atleast, if you set it to 0, you're basically telling MySQL, "Please insert the next id into this field."

                  现在,我想我可以将一个 INSERT 然后一个 UPDATE 查询放入我的 SQL 文件中,但是有没有办法告诉 MySQL 是的,我实际上想在这个字段中插入 0 吗?

                  Now, I suppose I could put an INSERT then an UPDATE query into my SQL file, but is there a way of telling MySQL in general that yes, I actually want to insert 0 into this field?

                  推荐答案

                  从答案中我得到了 这里:

                  您可以使用:

                  SET [GLOBAL|SESSION] sql_mode='NO_AUTO_VALUE_ON_ZERO'
                  

                  如此处所述,将防止 MySQL 将 0 的 INSERT/UPDATE ID 解释为下一个序列 ID.此类行为将被限制为 NULL.

                  Which as described here, will prevent MySQL from interpreting an INSERT/UPDATE ID of 0 as being the next sequence ID. Such behaviour will be limited to NULL.

                  不过,我认为应用程序的行为非常糟糕.您必须非常小心,以确保其始终如一地使用,尤其是如果您选择在以后实施复制.

                  It is what I'd consider pretty bad behaviour from the application though. You'll have to be real careful that it's used consistently, especially if you choose to implement replication at a later date.

                  这篇关于如何强制 MySQL 将 0 作为有效的自动递增值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
                    • <bdo id='rX6BO'></bdo><ul id='rX6BO'></ul>

                        <tfoot id='rX6BO'></tfoot>

                        1. <i id='rX6BO'><tr id='rX6BO'><dt id='rX6BO'><q id='rX6BO'><span id='rX6BO'><b id='rX6BO'><form id='rX6BO'><ins id='rX6BO'></ins><ul id='rX6BO'></ul><sub id='rX6BO'></sub></form><legend id='rX6BO'></legend><bdo id='rX6BO'><pre id='rX6BO'><center id='rX6BO'></center></pre></bdo></b><th id='rX6BO'></th></span></q></dt></tr></i><div id='rX6BO'><tfoot id='rX6BO'></tfoot><dl id='rX6BO'><fieldset id='rX6BO'></fieldset></dl></div>
                          <legend id='rX6BO'><style id='rX6BO'><dir id='rX6BO'><q id='rX6BO'></q></dir></style></legend>
                          • <small id='rX6BO'></small><noframes id='rX6BO'>

                              <tbody id='rX6BO'></tbody>