简体   繁体   English

SQL更新到自动增量列

[英]SQL update to auto-increment column

I am creating a test database. 我正在创建一个测试数据库。 I have a bunch of columns and I want to 'purge' the sensitive information so that I can work on it. 我有一堆列,我想“清除”敏感信息,以便我可以处理它。

id   email
1    email1@no-reply.com
2    email2@no-reply.com
#    email#@no-reply.com

basicall I want do do UPDATE table SET email = "email" + id + "@no-reply.com basicall我想做UPDATE table SET email = "email" + id + "@no-reply.com

I was going to do this in Python, but thought doing it in SQL would be easier. 我打算用Python做这个,但是想在SQL中做这件事会更容易。

For your case, it'll be: 对于你的情况,它将是:

UPDATE table
SET email = CONCAT( "email", id, "@no-reply.com" );

I just used it on my own table late of mysql. 我刚刚在mysql的late在我自己的桌子上使用它。 Here is the result: 结果如下:

mysql> update late
    -> set msg = concat( id, " ", msg );
Query OK, 74397 rows affected (4.15 sec)
Rows matched: 74397  Changed: 74397  Warnings: 0

Yes, if you are using update you should already have the id. 是的,如果您使用的是更新,那么您应该已经拥有了该ID。 If it was php it would look like: 如果它是php它看起来像:

$query = 'Update email set email="email'.$id.'@no-reply.com where email.id='.$id;

Where $query is the query string you are building and $id is the record id you are using to reference the record. 其中$query是您正在构建的查询字符串, $id是您用于引用记录的记录ID。

UPDATE table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]

For the single-table syntax, the UPDATE statement updates columns of existing rows in the named table with new values. 对于单表语法, UPDATE语句使用新值更新指定表中现有行的列。 The SET clause indicates which columns to modify and the values they should be given. SET子句指示要修改的列以及应该给出的值。 Each value can be given as an expression, or the keyword DEFAULT to set a column explicitly to its default value. 每个值都可以作为表达式给出,或者使用关键字DEFAULT将列明确设置为其默认值。 The WHERE clause, if given, specifies the conditions that identify which rows to update. WHERE子句(如果给定)指定标识要更新的行的条件。 With no WHERE clause, all rows are updated. 如果没有WHERE子句,则更新所有行。 If the ORDER BY clause is specified, the rows are updated in the order that is specified. 如果指定了ORDER BY子句, 则按指定的顺序更新行。 The LIMIT clause places a limit on the number of rows that can be updated. LIMIT子句限制了可以更新的行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM