日期:2014-05-18  浏览次数:20533 次

如何用SQL语句批量修改某个字段?
有表students如:
编号 班级 姓名
1  A     张三
2  A     李四
3  B     王五
4  B     赵六
5  A     郑七


现在要将全部A班的姓名改成“A-张三”的形式,请问SQL该如何写?

------解决方案--------------------
update students set 姓名= 'A- '+姓名 where 班级= 'A '
------解决方案--------------------
update students set 姓名=班级+ '- '+姓名

update students set 姓名=班级+ '- '+姓名 where 班级= 'A '
------解决方案--------------------
update students set 姓名=班级+ '- '+姓名 where 班级= 'A '
--OR
update students set 姓名= 'A- '+姓名 where 班级= 'A '

------解决方案--------------------
有表students如:
编号 班级 姓名
1  A   张三
2  A   李四
3  B   王五
4  B   赵六
5  A   郑七


现在要将全部A班的姓名改成“A-张三”的形式,请问SQL该如何写?

update students
set 姓名 = 'A- ' + 姓名
where 班级 = 'A '
------解决方案--------------------
update students set 姓名= 'A- '+姓名 where 班级= 'A '
------解决方案--------------------
---只更改A班人的姓名
Update students Set 姓名=班级+ '- '+姓名 Where 班级= 'A '

---更改所有姓名
Update students Set 姓名=班级+ '- '+姓名