积极答复者
【求助】如何修改整列数据等于另外一列?

问题
答案
-
-- 切换到临时库,创建测试表 use tempdb go create table Test (id int not null ,nums int null) -- 插入测试数据 insert into test (id,Nums) select 1,0 union all select 2,0 union all select 3,0 union all select 4,0 -- 检查数据 SELECT * FROM test /* id nums ----------- ----------- 1 0 2 0 3 0 4 0 (4 row(s) affected) */ -- 这里开始把Nums列变成ID的值 update Test set Nums=ID -- 检查结果 SELECT * FROM Test /* id nums ----------- ----------- 1 1 2 2 3 3 4 4 (4 row(s) affected) */
- 已标记为答案 ahdung_AI 2010年9月9日 6:13
全部回复
-
-- 切换到临时库,创建测试表 use tempdb go create table Test (id int not null ,nums int null) -- 插入测试数据 insert into test (id,Nums) select 1,0 union all select 2,0 union all select 3,0 union all select 4,0 -- 检查数据 SELECT * FROM test /* id nums ----------- ----------- 1 0 2 0 3 0 4 0 (4 row(s) affected) */ -- 这里开始把Nums列变成ID的值 update Test set Nums=ID -- 检查结果 SELECT * FROM Test /* id nums ----------- ----------- 1 1 2 2 3 3 4 4 (4 row(s) affected) */
- 已标记为答案 ahdung_AI 2010年9月9日 6:13