update 快速更新

数据库update总结

1、初始update

这种方式对仗工整,适用于初始属性赋值

update 表名 set 列名1=值1,列名2=值2,列名3=值3..... where 条件
2、普通update

这种方式适用于表关联赋值,适用范围最广

update 表名1 set 列名=(select 值 from 表名2 where 条件)
......
update 表名1 set (列名1,列名2,列名3....)=(select 值1,值2,值3..... from 表名2 where 条件)
3、快速update

这种方式的update必须保证两表匹配条件保证唯一,即将colnum设置为唯一,如此匹配会大大节省运行时间,用于解决数据量极大的情况

alter table table_1 modify colnum unique;
update (select a.xx a1,b.xx b1 from table_0 a,table_1 b
where a.colnum=b.colnum) set a1=b1;
总结

数据库初始化赋值选择方法一,数据量极大或提高效率使用方法三,在任意情况下均可使用方法二(其效率最低)。

原文地址:https://www.cnblogs.com/Zhao01/p/13404083.html