当前位置:网站首页>SQL update批量更新
SQL update批量更新
2022-06-27 16:16: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 student
set grade_id = (select grade_id from grade a where a.student_id=student.id)
where student.id in (select student_id from grade)
输出结果如下:
update有风险,操作须谨慎!朋友们

边栏推荐
- Ten common methods of arrays tools
- d3dx9_ How to repair 38.dll? d3dx9_ 38. How to download a missing DLL?
- Shardingsphere sharding proxy actual combat scenario
- 阅文、中文在线等网文平台如何布局数字藏品?未来是否会推出“Read/Write-to-Earn”产品?
- TP5 generates the most detailed two-dimensional code tp6 (also available)
- Wechat applet map displays the current position with annotation
- WOx WPM installing the Youdao plug-in
- TP5 restrict access frequency
- 「技术课堂」如何用 VSCode 从 0 到 1 改写 TDengine 代码
- Offline disk group
猜你喜欢
Teach you to use elastic search: run the first hello world search command
leetcode 19. Delete the penultimate node of the linked list
Teach you how to realize pynq-z2 bar code recognition
Sword finger offer 22 The penultimate node in the linked list
d3dx9_ What if 27.dll is lost? d3dx9_ How to repair 27.dll?
Asemi rectifier bridge kbp310 function pin diagram
Set up your own website (10)
Uploading multiple attachments from canvas apps to SharePoint
[Tang Laoshi] C -- encapsulation: member method
Asemi rectifier bridge kbp307 parameters, kbp307 details, kbp307 pictures
随机推荐
How much room does Migu video have for development without relying on sports events?
CDH cluster installation
国内首家!EMQ加入亚马逊云科技“初创加速-全球合作伙伴网络计划”
为什么要从 OpenTSDB 迁移到 TDengine
Allocate aligned heap space
The computer voice is blurry, the video is also out of the card, and the sound cannot be played. It is normal to insert the headset
Openssf security plan: SBOM will drive software supply chain security
Software testing learning - dark horse programmer, software testing learning outline
428-二叉树(501.二叉搜索树中的众数、701.二叉搜索树中的插入操作、450.删除二叉搜索树中的节点、669. 修剪二叉搜索树)
Asemi rectifier bridge kbp310 function pin diagram
Hospital reservation and registration system - system structure
Sword finger offer 22 The penultimate node in the linked list
Missing d3d10 How to repair DLL files? Where can I download d3d10.dll
Ten common methods of arrays tools
Application of scaleflux CSD 2000 in Ctrip
Seata server database connection user and service database undo_ What permissions do log users need?
InfluxDB集群功能不再开源,TDengine集群功能更胜一筹
d3dx9_ How to repair 33.dll? d3dx9_ What if 33.dll is lost?
(5) SPI application design and simulation verification 1 - logic sorting
软件测试基础-软件测试历史流程,分类,好处,限制