刚才没说明白,贴已结,发帖再问?
直接上代码吧drop table #tbcreate table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
select 'aaa' union all
select 'bbb' union all
select 'ccc' union all
select 'ddd' union all
select 'eee'
select *
from #tb/*(所影响的行数为 5 行)autoid 行号 b
----------- ----------- ----------
581080 NULL aaa
581081 NULL bbb
581082 NULL ccc
581083 NULL ddd
581084 NULL eee(所影响的行数为 5 行)*/--我想用代码加上行号,实现
/*
autoid 行号 b
----------- ----------- ----------
581080 1 aaa
581081 2 bbb
581082 3 ccc
581083 4 ddd
581084 5 eee(所影响的行数为 5 行)*/
直接上代码吧drop table #tbcreate table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
select 'aaa' union all
select 'bbb' union all
select 'ccc' union all
select 'ddd' union all
select 'eee'
select *
from #tb/*(所影响的行数为 5 行)autoid 行号 b
----------- ----------- ----------
581080 NULL aaa
581081 NULL bbb
581082 NULL ccc
581083 NULL ddd
581084 NULL eee(所影响的行数为 5 行)*/--我想用代码加上行号,实现
/*
autoid 行号 b
----------- ----------- ----------
581080 1 aaa
581081 2 bbb
581082 3 ccc
581083 4 ddd
581084 5 eee(所影响的行数为 5 行)*/
select 'aaa' union all
select 'bbb' union all
select 'ccc' union all
select 'ddd' union all
select 'eee'
declare @i int
set @i = 0
update #tb
set 行号 = @i,@i+=1select *
from #tbautoid 行号 b
----------- ----------- ----------
581080 1 aaa
581081 2 bbb
581082 3 ccc
581083 4 ddd
581084 5 eee(5 行受影响)
create table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
select 'aaa' union all
select 'bbb' union all
select 'ccc' union all
select 'ddd' union all
select 'eee'update #tb
set 行号 =autoid-581079
select *
from #tbdrop table #tb--581080 1 aaa
--581081 2 bbb
--581082 3 ccc
--581083 4 ddd
--581084 5 eee
set @i = 0
update #tb set @i=行号=@i+1select *
from #tb
借用一下數據
declare @i int
set @i = 0
update #tb set @i=行号=@i+1select *
from #tb