测试
1、set一个字段
在表t_test中设置第二条记录(bs为2)的password为'***'。
update t_test t
set t.password = '***'
where t.bs = 2;
2、set多个字段
在表t_test中设置第一条记录(bs为1)的password为'*'、remark为'*'。
update t_test t
set t.password = '*', t.remark = '*'
where t.bs = 1;
3、set null值
在表t_test中设置第三条记录(bs为3)的password为null、remark为null。
update t_test t
set t.password = null, t.remark = null
where t.bs = 3;
这个是按照标准语法写的,在不同的数据库系统中,update还有更多的写法,但是标准写法都是支持的。以上三个例子为了说明情况,每次都更新一行。在实际中,可以通过where语句约束来控制更新行数。
1、set一个字段
在表t_test中设置第二条记录(bs为2)的password为'***'。
update t_test t
set t.password = '***'
where t.bs = 2;
2、set多个字段
在表t_test中设置第一条记录(bs为1)的password为'*'、remark为'*'。
update t_test t
set t.password = '*', t.remark = '*'
where t.bs = 1;
3、set null值
在表t_test中设置第三条记录(bs为3)的password为null、remark为null。
update t_test t
set t.password = null, t.remark = null
where t.bs = 3;
这个是按照标准语法写的,在不同的数据库系统中,update还有更多的写法,但是标准写法都是支持的。以上三个例子为了说明情况,每次都更新一行。在实际中,可以通过where语句约束来控制更新行数。
本文详细介绍了如何使用SQL的UPDATE语句来修改数据库表中的记录,包括设置单一字段、多个字段以及将字段值设为NULL的方法,并通过实例展示了如何精确控制更新的行数。
2812

被折叠的 条评论
为什么被折叠?



