当前位置:网站首页>SQL update批量更新
SQL update批量更新
2022-06-27 18:36:00 【墨天輪】
首先回顧下,sql update語句是用於修改錶中的數據。
語法:
UPDATE 錶名稱 SET 列名稱 = 新值 WHERE 列名稱 = 某值
SQL update批量更新實例
1、通過同一錶內update複制列到另一列,如下圖所示,在原錶增加列score2,且把score的值複制過來

update student set score2= score
輸出結果

如果是异錶數據更新過來呢?應該怎麼操作?請往下看~
2、特殊情况下,某錶需要增加列外鍵與另一錶(可能是另一個庫的錶)關聯,這種情况由於沒有關聯性,往往通過紙質資料做電子錶格再做臨時錶來通過批量更新關系數據
如student 錶,需要增加列grade_id

另一張臨時錶Grade錶(可能是電子錶格導入的臨時錶)如下:

現需求在student錶上增加的Grade_id對應賦值,語句如下 :
update studentset grade_id = (select grade_id from grade a where a.student_id=student.id)where student.id in (select student_id from grade)
輸出結果如下:

update有風險,操作須謹慎!朋友們

边栏推荐
- 写在eclipse里面,与数据库连接查询之后的问题
- TDengine在数控机床监控中的应用
- 时序数据库(Time Series Database)的存储引擎要想做到极致,还得自研
- JXL export Excel
- LACP details
- Wechat applet map displays the current position with annotation
- Explain the distributed computing of Apache skywalking OAP in detail
- Market status and development prospect forecast of global off-road recovery rope industry in 2022
- leetcode 70. climb stairs
- wheel ui
猜你喜欢

Teach you how to realize pynq-z2 bar code recognition

Wechat applet association search

Study on heritability and field experiment design

07. Express routing

On array-_-
![Contest3182 - the 39th individual training match for 2021 freshmen_ C: [string] ISBN number](/img/98/11ca12889a1b653ce8158920bf5136.jpg)
Contest3182 - the 39th individual training match for 2021 freshmen_ C: [string] ISBN number

Simple anti shake for wechat applet

Wanzhou gold industry: what knowledge points do you need to master to invest in precious metals?

Wanzhou gold industry: what are the common gold investment and warehouse building modes?

leetcode 19. Delete the penultimate node of the linked list
随机推荐
How much room does Migu video have for development without relying on sports events?
Simple anti shake for wechat applet
Application of scaleflux CSD 2000 in Ctrip
数据同步工具 DataX 已经正式支持读写 TDengine
Part 31 supplement (31) ECMAScript conversion to string and number
ROS "topic" programming implementation
【协会通知】关于举办人工智能与物联网领域暑假专题师资培训的通知
Redis installation
Alibaba cloud server is invaded
New products, new personnel and new services, Infiniti will continue to plough into China's future!
Set up your own website (10)
Advanced learning of MySQL -- Application -- Optimization of other SQL statements
07. Express routing
Wechat applet association search
[the way of programmer training] - 3 Character count statistics
Generate zip package command
Wanzhou gold industry: what are the common gold investment and warehouse building modes?
手把手教你在Windows 10安装Oracle 19c(详细图文附踩坑指南)
seata-server 端数据库连接用户、业务数据库 undo_log 所属用户都需要什么权限?
[Tang Laoshi] C -- encapsulation: member method