update tb set colA=colA/2 --应该是这样 --这句话的意思是修改表TB的COLA列,使它变为原来COLA的一半
declare @t table (colA int) insert into @t select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7update @t set colA=colA/2 select * from @t /* colA ----------- 1 1 2 2 3 3 */ --我们再定义一个表变量 declare @m table (colA decimal(4,2)) insert into @m select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7update @m set colA=colA*0.5 select * from @m /* colA --------------------------------------- 1.00 1.50 2.00 2.50 3.00 3.50 */
update tb set colA/2 where --条件。
--查找
select colA from tb where -- 条件。
update tb set colA/2 where --条件。
--查找
select colA/2 from tb where -- 条件。
修改一下
第一句,update 更新 tb 表名,set 设置 colA 列值 /2 减半
如果没条件的话,就不要加where 如果有条件,就加个where 后面跟你所要更新的条件
比如说 你要修改哪一行的数据。把行号 id = 。。 写出来
第二句你自己翻译把
查询
--应该是这样
--这句话的意思是修改表TB的COLA列,使它变为原来COLA的一半
declare @t table (colA int)
insert into @t
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7update @t set colA=colA/2
select * from @t
/*
colA
-----------
1
1
2
2
3
3
*/
--我们再定义一个表变量
declare @m table (colA decimal(4,2))
insert into @m
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7update @m set colA=colA*0.5
select * from @m
/*
colA
---------------------------------------
1.00
1.50
2.00
2.50
3.00
3.50
*/