English 中文(简体)
SQL 更新为自动插入列
原标题:SQL update to auto-increment column
  • 时间:2012-05-25 06:27:11
  •  标签:
  • mysql
  • sql

我正在建立一个测试数据库。我有一堆专栏,我想清理敏感信息,以便我能处理。

id   email
1    [email protected]
2    [email protected]
#    email#@no-reply.com

我想要做的基本工作是 UPDATE Table SET 电子邮件 = "email" + id+ "@no-reply.com

我本来想在皮顿做这个的, 但以为在SQL做会更容易些。

最佳回答

对于你的情况,这将是:

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

我刚刚用在我自己的桌子上late of mysql。 以下是结果:

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

是的, 如果您正在使用更新, 您应该已经拥有 ID 。 如果是 php, 看起来像 :

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

此处 $query 是您正在构建的查询字符串, $id 是您用于引用记录的记录代号。

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

对于单表语法, < 强度> UPDATE 语句以新值更新指定表格中现有行列的值。 < 强度> SET < /强度 > 条款指定了要修改的列和应给定的值。 每种值都可以以表达式表示, 或关键词 < 强度 > DefAUTE 来设定一个直观的列。 如果给定了 < 强度 > where 条款, 则指定了要更新的行的条件。 在 < 强度 > no hher < /强度 > 条款中, 所有行都会更新。 如果指定了 < 强度 > ORDER < by < 强度 > /强度 > 条款, 则按指定的顺序对行进行更新。 < 强度 > LIMIT < /强度 > 条款对可以更新的行数设置限制。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签