???? ?????? IDENTITY ??? ????????? ?? SELECT INTO ?? INSERT ????????? SELECT ???? ????? ??? ???? ORDER BY

?????? ????????? ?????? ?????????
???? ???????: 273586 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

??? ??????? ??????? SELECT INTO ?? ?????? IDENTITY ? ???? ORDER BY ?? ??? ???? ??? ??????? ???? ??? ??????? ???? ???? ??????? ??? ?? ??????? ???? ?? ?????? ?????? ORDER BY. ??? ???? ??????? ??? ???? ?????? IDENTITY ?? ??????? 1 ? ????? 1, ?? ???? ???? ????? ?? ?????? ??????? ??????? ???? ?????? ?? 1? ? ???? ?????? ?? ????? ???? ?????? ?? 2 ??? ??? ????? ?? ???? forth.While ??? ?? ?????, ?? ??? ???? ??????. ?? ???? ???? TOP ?? SET ROWCOUNT ????? ????? ??????.

??? ???? ??? IDENTITY ????? ?????? ??????? ???? ??????? ?? ????? ORDER BY ????? ???? ???? ????? ??? ???? ?? ??????? IDENTITY ?? ?? ?????? INSERT SELECT ????????? ? ORDER BY ?????? ??? ??????.

??????? ????

????? ??? ??????? ???? ?? ??????? ??? ???? ?????? GetIdentity() ?? ???? ????????? (showplan) ???? ?? ????? ????? ??????? ?????? ??? ????????? ?????? ?? ???? ROWCOUNT TOP/SET. ????? ?? ??? ????? ????????? ???? SELECT INTO ?? ???? IDENTITY ? ???? ORDER BY ????? ????? ?? ????? ???? ??? ?????? ??? ????? ?????? ?? ???? ?????. ????? ????? ????????? ??????? ????? SELECT INTO ? ???? IDENTITY.

?? ???? ???????? ???? ???? OldTable ?? ????? ???????.
Col1      Col2
-------   --------
1         A          
11        F 
7         G          
17        I          
2         Z          

????????? 1

?? ??? ?????????? ????????? SELECT INTO ?????? ???? IDENTITY ORDER ????.
SELECT	Col1, Col2, ID=IDENTITY (int, 1, 1)
INTO 	NewTable
FROM 	OldTable
Order By Col1
NewTable ?? ???? ????? ???????? ???? ???? ??? ??? ???????.

??????? ??????

Col1      Col2       ID
-------   --------   --------
1         A          4
2         Z          2
7         G          5
11        F          3
17        I          1
?? ????? ?? ?????? IDENTITY ???? ???? SQL ??? ???? ??????? ??? ?????? ORDER BY (????1) ?? ?????????.

??????? ???????

Col1     Col2       ID
-------  --------   -------
1        A          1
2        Z          2
7        G          3
11       F          4
17       I          5
?? ??? ??????? ?? ????? ?? IDENTITY ???? ??? SQL Server ?????? ?? ??? ??????? ??????? ORDER BY (????1) ?? ????????? ??????. ??? ????? ?? ???? ??? coincidental ??? ??? ????? ?????? ??? ???? ?? ?? ??? ??? ???? ????? ?????????.

????????? 2

????????? SELECT INTO ??????? ?????? IDENTITY ?????? ???? ORDER BY ? ?? ???? ????? TOP ?? ????? SET ROWCOUNT.
SELECT TOP 3 Col1, Col2, ID=IDENTITY (int, 1, 1)
INTO NewTable
FROM OldTable
Order By Col1
- ?? -
SET ROWCOUNT 3
SELECT Col1, Col2, ID=IDENTITY (int, 1, 1)
INTO NewTable
FROM OldTable
Order By Col1
NewTable ?? ???? ????? ?? ?????? ???????? ?? ??? ????????? ??????? ???? ??? ????:

??????? ??????

Col1   Col2   ID
-----  -----  -----
1      A      2
2      Z      1
7      G      3
?? ??? ??????? ?? ??? ?? ?????? IDENTITY ???? ???? SQL ??? ???? ??????? ??? ?????? ORDER BY (????1) ?? ?????????.

??????? ???????

Col1    Col2     ID
------  ------   ------
1       A        1
2       Z        2
7       G        3
?? ??? ??????? ?? ????? ?? IDENTITY ???? ??? SQL Server ?????? ?????? ?? ??? ??????? ??????? ORDER BY (????1) ?? ?????????. ??? ????? ?? ???? ??? coincidental ??? ??? ????? ?????? ??? ???? ?? ?? ??? ??? ???? ????? ?????????.

??????? ???????

Col1   Col2    ID
------ ------  ------
1      A       4
2      Z       2
7      G       5
?? ??? ??????? IDENTITY ?????? ???? ???? SQL Server ??? ???? ??????? ??????? ORDER BY (????1) ?? ?????????. ???????? ??? ???? ?? ????? ???????? ????? ?????? ???????? ????? ?????? ?? ?????? IDENTITY ?? ????????? (???? = 1? ????? = 1).

?? ?????? ?????? ???? IDENTITY ??? ??????? ???????? ??? ???????? ???? ? ????? ???? ????. ??? ???? ???? ????? ???? ???? ??? ?? ??? ??? ?????? ???????? ??? ORDER BY. ????? ??? ??????? ???? ????? TOP ?? ROWCOUNT SET ???? ???? ?????? ??????? ?? ?????? ?????? (NewTable) ?? ???? ???? ??? ??????? ??? ????. ?? ?? ?????? ?? ??? ??????? ???? ???? SQL ?????? ??????? ????? ?????? IDENTITY.

????? ??? ???? ????? INSERT INTO SELECT FROM ?? ORDER BY.

?? ???? ???????? ???? ???? OldTable ?? ????? ???????:
Col1      Col2
-------   --------
1         S          
11        F 
7         G          
17        I
2         z


???? ????? ?????? ????? ?????? NewTable (????? ???? ?????)
ID (identity)    Col1     Col2
---------------    -------   ------


??? ???? INSERT INTO SELECT FROM ????????? ?????? ?? ???? ORDER BY ??? ?????? ???? ?? NewTable ???? ??????? ??? ????1.
INSERT INTO NewTable (Col1, Col2) SELECT Col1, Col2 FROM OldTable ORDER BY Col1 
ID (identity)    Col1     Col2
-------------    ------   ------
1                1         S
2                2         z
3                7         G
4                11        F
5                17        I

?????? ??? ????? ???? ????? ???? ???? ???? ??????? ?? ?????? 1. ??? ???? INSERT INTO ?? ???? ??????? ?????? ?????? ?? ????1 ?? NewTable. ???????? ???????? ?? ????? ??????? ???? ORDER BY ????? ??? ?? ???? ?????? ????? SELECT:
SELECT * from NewTable ORDER BY ID

???????

???? ???????: 273586 - ????? ??? ??????: 21/????/1428 - ??????: 4.2
????? ???
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server 2000 Desktop Engine (Windows)
  • Microsoft SQL Server 2000 Developer Edition
  • Microsoft SQL Server 2000 Enterprise Edition
  • Microsoft SQL Server 2000 Personal Edition
  • Microsoft SQL Server 2000 Standard Edition
????? ??????: 
kbmt kbhowto kbinfo kbpending KB273586 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????273586

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com