SELECT ??? ?? ???????? ???? ?? ??? ????? ???? ???? ?? ?? ????? ?????? ?? ??????? ?????? ??? ORDER BY ??? ?? ??? ???? ????????

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

?? ????? ??

??????

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

??? ?? ????? ????????ORDER BY ???, ??? ???????? ???????? ?????? ??????? ??? ????? ???? ?? ??? ??? ????? ?????? ???? ????? ?? ??? ??? ?????????????? ?? ???? ??? ?? ?? ???????? ???? ?? ?????? ????????? ???? ?? ??? ? ORDER BY ?????? SELECT ???

???? ???????

????? ??? ?? ????? ???? ??? ?? ?? ?? ?????? ?? ?????? ???? ???GetIdentity()?????? ?????? ???? ??? (showplan), ?? ??????????? ????????, ?????? ?????? ??????? ?? TOP/SET ROWCOUNT ?? ???????? ?? ???? ??? ???? ??? ?????? ???????? ?? ??? ???? ??? ?? ?? SELECT ??? ?? ????????????? ?? ?? ORDER BY ??? ????? ???? ??????? ?? ?? ????????? ???? ?? ?? ??????? ?? ???? ??? ???? ?? ?? desire ?? ???? ??? ???????????????? ???????? ??? SELECT ??? ??? ?????? ?? ?? ????????????? ?? ??? ???? ???..

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

1 ????????

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

?????? 1:

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

???? 2

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

???????? 2

????? SELECT ??? ??????? ????? ?????? ?? ?? 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?? ???? ?? ???????? ?? ?? ????? ????????? ?? ??? ????? ??? ???? ????? ?? ???? ?? ???:

?????? 1:

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

???? 2

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

???? 3

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

?????? ???,??????????? ??? ?? ??? ?? ?????? ???????? ?? ?????? ????? ??? ????? ??? ???????, ????? ??? ????? ???? ??? ????????? ORDER BY ??? ?? ?????? ????? ???? ?? ????? ?????, ?? ?? ???? TOP ?????? ?? ????? SET ROWCOUNT ???, ????????? ??????? ?????? (??? ???????? ????NewTable) ??? ????? ??? ???? ??????? ????? ????? SQL Server ????? might ?? ??? ?? ?????? ???????? ?? ??? ??????????????? ?? ??? ???? ???..

???? ?? ?????? ?? ?? ???? ???????? ??? SELECT ?? ORDER BY ??? ?? ??? involves ???

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


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


????? ???????? ??? SELECT ?? ?????? ?? ORDER BY ??? ?? ??? ?? ?????? ?? ???? ????? ??? IDNewTable?? ??? ??? ??? ???? ??? ??Col1.
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

???:ID ????? ????? ?? ??? ??? ?? ?? ???? ?? ??? ????? ??Col1. ?? ??????, ??????? ??? ???????? ???? ?? ?? ID ?? ????? ???? ??Col1???NewTable. ?????? ???? ??? ???? ?? ???? ????, ?? ORDER BY ??? ?????? ?? ?? ??? ???? ??? ????? ?????? ?????? ??????:
SELECT * from NewTable ORDER BY ID

???

???? ID: 273586 - ????? ???????: 02 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server 2000 Developer Edition
  • Microsoft SQL Server 2000 Enterprise Edition
  • Microsoft SQL Server 2000 Personal Edition
  • Microsoft SQL Server 2000 Standard Edition
??????: 
kbhowto kbinfo kbpending kbmt KB273586 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??: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