MariaDB教程

MariaDB 更新数据

在MariaDB中,UPDATE语句用于通过更改表中的值来修改现有字段。
语法:
UPDATE table_name SET field=new_value, field2=new_value2,...
[WHERE ...]
UPDATE语句可与WHERE,ORDER BY和LIMIT子句一起使用。
UPDATE table
SET column1 = expression1,
    column2 = expression2,
    ...
[WHERE conditions]
[ORDER BY expression [ ASC | DESC ]]
[LIMIT number_rows]; 
示例:

更新单列

我们有一个表格" Students",其中包含以下数据:
Mariadb Update 1
让我们更改" student_name"为" Ajeet"的学生名" Aryan"。
UPDATE Students
SET student_name = 'Aryan'
WHERE student_name = 'Ajeet'; 
Mariadb Update 2
查询成功执行。现在检查更新的数据:
输出:
Mariadb Update 3
Example2:

更新多列

您也可以使用MariaDB数据库中的UPDATE满足条件更新多个列。在下面的示例中,我们更新表" Students"中" student_name"为" Alecia"的两列" student_name"和" student_address"。
UPDATE Students
SET student_name = 'Maria',
 student_address = 'Goa'
WHERE student_name = 'Alecia'; 
Mariadb Update 4
这些列现在已更新。您可以使用SELECT语句检查并验证结果:
SELECT * FROM Students; 
输出:
Mariadb Update 5
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4