simker

Life is too short, just make it.


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

  • 音乐

  • 搜索

sql语句之update笔记

发表于 2021-02-22 分类于 SQL 阅读次数: Disqus:
本文字数: 839 阅读时长 ≈ 1 分钟

sql 语句更新篇

基础篇

  • 基本赋值更新
1
update [table] set [field] = [value] where [where case];
  • 自增、自减等
1
2
3
4
5
6
update [table] set [field] = [field] + 1 where [where case];
update [table] set [field] = [field] - 1 where [where case];
update [table] set [field] = [field] * 1 where [where case];
update [table] set [field] = [field] / 1 where [where case];

update [table] set [field] = [field] + [an other field] where [where case];
  • 更新多个字段

在set后面用逗号隔开便可

1
update [table] set [field] = [field] + 1, [field2] = 2 where [where case];
  • 更新记录数量限制等

和查询一样,更新也是可以接收 order by, limit 的;

1
update [table] set [field] = [field] + 1, [field2] = 2 where [where case] order by [field] limit [limit] offset [offset];
  • 替换更新

写入了记录发现要批量更新,但是只能更新字段的一部分,这时候就可以用替换了

以下是清理图片后缀的语句.

1
update [table] set `image` = REPLACE(`image`, '.png', '')where `image` LIKE '%.png%';
  • 字符串合并

这个很少会用到,一般是在存储过程里面使用

以下是我当初维护数据时,为了清除重复数据做出的标记改动,以便我新增唯一索引

1
update [table] set union_data = concat(`union_data`,'-',`id`) where [where case];

To be continue

Cai xian 微信支付

微信支付

Cai xian 支付宝

支付宝

# notes
PHP梳理之array
sql语句之query笔记
  • 文章目录
  • 站点概览
Cai xian

Cai xian

A super nice guy!
24 日志
12 分类
15 标签
  1. 1. 基础篇
© 2019 – 2021 Cai xian | 70k | 1:04
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Pisces v7.3.0
|