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

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

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

        php/mysql 防止多列重复条目

        php/mysql prevent duplicate entries over multiple columns(php/mysql 防止多列重复条目)

      1. <tfoot id='kGMCm'></tfoot>

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

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

                  本文介绍了php/mysql 防止多列重复条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想提出一个标准做法,以防止任何表格在重要的地方出现重复.在大多数情况下,重复是变量的组合,而不是一个.我的主键只是每个字段的唯一 ID,所以我不能使用它们.我一直在做的是先查询表,然后如果相关组合的行数为 0,则进行插入.但是,我已阅读应该可以在多个字段上设置唯一键以强制唯一性.INSERT IGNORE 听起来很可能,但是,我需要在多个列上忽略它.

                  I would like to come up with a standard practice to prevent any tables from having duplicates where it matters. In most cases duplicates are a combination of variables rather than one. My primary keys are just the unique ids for each field so I cannot use them. What I have been doing is querying the table first and then if the number of rows for the combination in question is 0, making the insert. However, I have read it should be possible to set up a unique key over multiple fields to enforce uniqueness. INSERT IGNORE sounds like a good possibility, however, I would need it to ignore on more than one column.

                  例如,对于字段followers 和followed,一个表中可以有多个followers 和followers,但只能是两者的一种组合.

                  As an example, with the fields followers and followed, there can be multiple followers and followeds in a table but should only be one combination of both.

                  谁能建议语法首先在多个字段上创建唯一键,然后执行 SQL 插入查询以防止欺骗?非常感谢.

                  Can anyone suggest syntax first to create the unique keys over multiple fields and then to do a SQL insert query that prevents dupes? Many thanks.

                  推荐答案

                  您可以简单地在这些列上创建一个多列索引并强制唯一性:参见 MySQL 手册 http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html.

                  You can simply create a multiple-column index on these columns and enforce uniqueness: see the MySQL manual at http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html.

                  例如,在具有 id(唯一主键)、colAcolB 列的表中,您运行:

                  For example, in a table with columns id (unique primary key), colA and colB, you run:

                  ALTER TABLE table ADD UNIQUE KEY (colA,colB)
                  

                  就是这样:导致这两列组合中重复条目的任何 INSERT 现在将返回 MySQL 错误,而不是通过.如果您使用 INSERT IGNORE,如果执行它会违反此唯一约束,则不会引发 MySQL 错误,并且您的 INSERT 语句将被悄悄地忽略.

                  This is it: any INSERTs leading to a duplicate entry in these two columns combined will now return a MySQL error instead of going through. If you use INSERT IGNORE, no MySQL error will be thrown if executing it would violate this unique constraint, and your INSERT statement would be quietly disregarded.

                  这篇关于php/mysql 防止多列重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                    <tfoot id='MOukk'></tfoot>

                        <tbody id='MOukk'></tbody>

                      1. <legend id='MOukk'><style id='MOukk'><dir id='MOukk'><q id='MOukk'></q></dir></style></legend>

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

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

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