SQL Server:复制表中的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/173717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:47:11 来源:igfitidea点击:
SQL Server: Copying column within table
提问by Hoopy Frood
What is the easiest way to copy the all the values from a column in a table to another column in the same table?
将表中一列的所有值复制到同一表中的另一列的最简单方法是什么?
回答by Panagiotis Korros
With a single statement (if the columns have the same datatype)
使用单个语句(如果列具有相同的数据类型)
UPDATE <tablename>
SET <destination column name> = <source column name>
回答by Ilya Kochetov
This script will update ALL values in the field1 with the values from the field2 in the corresponding row
此脚本将使用相应行中 field2 中的值更新 field1 中的所有值
UPDATE table SET field1 = field2