데이터가..
no
-------------------------------
1
2
3
4
6
7
8
10
이렇게 있을때
5,9 가 없는 상황일때
6,7,8,10 을 5,6,7,8 로 바꾸어 되는데요
------------------------------------
5
이렇게 할려면 어케 해야될런지...
우선은 꼭 그렇게 하셔야 하는 것이라면 방법이 없는 것은 아닙니다.
그런데 Data가 많아지면 힘든 처리시의 시간이 증가할 것인데
꼭 빠진 identity의 값을 그렇게 정리하셔야 하는 것인가요?
그것부터 고민을 하셔야 할 듯하네요.
다음은 그 과정입니다.
/*
--데이터 만들기create table testTB (a int)
insert into testTB values(1)insert into testTB values(2)insert into testTB values(3)insert into testTB values(4)insert into testTB values(6)insert into testTB values(7)insert into testTB values(9)insert into testTB values(10)*/
select * from testTB --데이터 확인
create table #testTB (idx int identity(1,1), a int) --identity를 가진 템프테이블 만들기
insert into #testTB (a) select a from testTB --템프테이블에 a의 자료를 삽입
select * from #testTB --템프테이블의 데이터 확인
update #testTB set a = idx where a <> idx --업데이트를 해보고
select * from #testTB --데이터 확인
지금은 하나만 했지만 만약 전체의 자료를 이용한다면 #table을 이용하여 select into구문을 이용해서 새로운 테이블을 만들거나
또는 update를 거치게 되면 가능하리라 봅니다.