首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

uodate语句解决方案

2012-03-23 
uodate语句createtabletest(pk_idvarchar(20))insertintotestselect290insertintotestselect290insertinto

uodate语句
create   table   test
(

pk_id   varchar(20)

)
insert   into   test   select   '290 '
insert   into   test   select   '290 '
insert   into   test   select   '290 '
insert   into   test   select   '290 '
insert   into   test   select   '290 '
insert   into   test   select   '290 '

--Update   A   Set   pk_id   =   (Select   Count(*)   From   test   Where   pk_id   <=   A.pk_id)   From   test   A

select   *   from   test
/*
写一句update语句,把pk_id列更新为 '1 ', '2 ', '3 '.....依次递增

name                

1                        
2                        
3                        
4                        
5                        
6                        
*/
drop   table   test

[解决办法]
create table test
(

pk_id varchar(20)

)
insert into test select '290 '
insert into test select '290 '
insert into test select '290 '
insert into test select '290 '
insert into test select '290 '
insert into test select '290 '

Declare @I Int
Select @I = 0
Update test Set pk_id = @I , @I = @I + 1

select * from test
[解决办法]
declare @ID int
SET @id = 0
UPDATE test SET
@id = @id + 1,
pk_id = @id
select * from test

热点排行