2013-06-03 4 views
0

테이블에 이미 5000 개의 행이 채워진 테이블이 있습니다.레코드가 이미있는 테이블에서 행 수를 만드는 방법은 무엇입니까?

나는 SEQN이라는 열을 가지고 있습니다.

이 열에 행 수를 입력하고 싶습니다.

내가 사용하고 있습니다 :

마이크로 소프트 SQL Server Management Studio를 9.00.4035.00 마이크로 소프트 분석 서비스 클라이언트 도구 2005.090.4035.00 Microsoft 데이터 액세스 구성 요소 (MDAC) 6.1.7601.17514 마이크로 소프트 MSXML 3.0 4.0 5.0 6.0 마이크로 소프트 인터넷 Explorer 9.0.8112.16421 Microsoft .NET Framework 2.0.50727.5466 운영 체제 6.1.7601

고맙습니다.

SQLNewbie

+0

는 주문에 대한 모든 기본 설정을하거나 할 것입니다 5000 충분할 통해 하나의 유통? – HABO

+0

모든 배포 괜찮을 것이다 ... 두 번째 생각에 – scottgobucks

+0

감사 ... 타임 스탬프에 의해 잘 작동합니다 ... 감사합니다 – scottgobucks

답변

0
declare @Foo as Table (FooId Int Identity, Sequence Int, Timestamp DateTime); 
insert into @Foo (Sequence, Timestamp) values 
    (42, '20010203 10:18:05'), (18, '20100508 22:18:05'), (NULL, '19960316 19:00:00'); 

select * from @Foo order by Sequence; 

update Foo 
    set Sequence = S 
    from (select Sequence, Row_Number() over (order by Timestamp) as S from @Foo) as Foo; 

select * from @Foo order by Sequence; 

update Foo 
    set Sequence = S 
    from (select Sequence, Row_Number() over (order by Timestamp desc) as S from @Foo) as Foo; 

select * from @Foo order by Sequence;