【MySql】update用法

update 语句可用来修改表中的数据, 简单来说基本的使用形式为:

update 表名称 set 列名称=新值 where 更新条件;

以下是在表 students 中的实例:

将 id 为 5 的手机号改为默认的 - : update students settel=default where id=5;

将所有人的年龄增加 1: update students set age=age+1;

将手机号为 13288097888 的姓名改为 "小明", 年龄改为 19: update students setname="小明", age=19 wheretel="13288097888";

UPDATE替换某个字段中的某个字符

当我们需要将字段中的特定字符串批量修改为其他字符串时,可已使用以下操作:

UPDATE table_name SET field=REPLACE(field, 'old-string', 'new-string') 
[WHERE Clause]

实例:

以下实例将更新 runoob_id 为 3 的runoob_title 字段值的 "C++" 替换为 "Python":

UPDATE runoob_tbl SET runoob_title = REPLACE(runoob_title, 'C++', 'Python') where 
runoob_id = 3;
原文地址:https://www.cnblogs.com/zyber/p/9581115.html