SQLServer修改表数据

使用SSMS数据库管理工具修改数据

修改任意一条或者多条都可以

1:打开数据库,选择数据表,右键点击-》编辑所有行(如未配置,点击编辑前200行)。

2、编辑需要修改的数据-》编辑完成后,右键点击空白处-》选择执行SQL即可编辑成功。

使用T-SQL脚本修改数据

修改单表中一行单列或者多列数据

语法:update 表名 set 列名1=值,列名2=值 where 条件;

示例一:update test1  set age='21' where id='1';

示例结果:

修改单表中多行一列或多列数据

语法:update top(数量) 表名 set 列名1=值1,列名2=值2 where 条件;

示例:

update test1 set age='23' where id in ('1','2');

update test1 set age='22' where id between '3' and '4';

update test1 set age='23' where id>='5' and id <='6';

update top(2) test1 set age='23' where id>='5';

update test1 set age='23' where test1.id in (select top(2) id from test1 order by id desc);

示例结果:

多表关联修改表中数据

语法:update 表1 set 表1.列1=值,表1.列2=值 from 表1 as a,表2 as b where a.列名=b.列名;

示例:update test1 set test1.name='李华',test1.sex='女' from test1 as a,test2 as b where a.classid=b.id;

示例结果:

总结:修改数据表数据,灵活组合修改数据列,数据源,查询条件是关键。

  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值