批量修改MySQL表的值[重复]

时间:2021-09-13 16:38:22

This question already has an answer here:

这个问题在这里已有答案:

I would like to add "AAI=" to all values in a table in MySQL.

我想在MySQL的表中为所有值添加“AAI =”。

For example:

例如:

  • Value 1 = 123
  • 值1 = 123
  • Value 2 = 234
  • 值2 = 234
  • Value 3 = 345
  • 值3 = 345

After modify:

修改后:

  • Value 1 = 123AAI=
  • 值1 = 123AAI =
  • Value 2 = 234AAI=
  • 值2 = 234AAI =
  • Value 3 = 345AAI=
  • 值3 = 345AAI =

Thank and best regards.

谢谢,最好的问候。

3 个解决方案

#1


1  

Quite simple, you can use the MySQL CONCAT function to do this.

很简单,您可以使用MySQL CONCAT功能来执行此操作。

So if you want to update and append text to the end of every single value in a column, you can do the following query:

因此,如果要更新文本并将其附加到列中每个值的末尾,则可以执行以下查询:

UPDATE table SET columnName = CONCAT(columnName, 'AAI=');

#2


0  

1.First get data from your database 2.Looping data 3.Update your new value (eg:AAI=) This is example :

1.首先从您的数据库获取数据2.Looping数据3.更新您的新值(例如:AAI =)这是示例:

    $query = mysqli_query($connection,"SELECT * FROM your table");
    foreach($query as $key=>$value){
      $data = $value;
      $newValue = $value.'AAI=';
      $newQuery = mysqli_query($connection," UPDATE your table SET $data = '$newValue' ");
//Here you can add button to update data
    }

#3


0  

UPDATE {tablename} SET {fieldname} = CONCAT('AAI= ', {fieldname})

UPDATE {tablename} SET {fieldname} = CONCAT('AAI =',{fieldname})

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat

#1


1  

Quite simple, you can use the MySQL CONCAT function to do this.

很简单,您可以使用MySQL CONCAT功能来执行此操作。

So if you want to update and append text to the end of every single value in a column, you can do the following query:

因此,如果要更新文本并将其附加到列中每个值的末尾,则可以执行以下查询:

UPDATE table SET columnName = CONCAT(columnName, 'AAI=');

#2


0  

1.First get data from your database 2.Looping data 3.Update your new value (eg:AAI=) This is example :

1.首先从您的数据库获取数据2.Looping数据3.更新您的新值(例如:AAI =)这是示例:

    $query = mysqli_query($connection,"SELECT * FROM your table");
    foreach($query as $key=>$value){
      $data = $value;
      $newValue = $value.'AAI=';
      $newQuery = mysqli_query($connection," UPDATE your table SET $data = '$newValue' ");
//Here you can add button to update data
    }

#3


0  

UPDATE {tablename} SET {fieldname} = CONCAT('AAI= ', {fieldname})

UPDATE {tablename} SET {fieldname} = CONCAT('AAI =',{fieldname})

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat