| Author |
Topic |
|
newprog
Starting Member
5 Posts |
Posted - 2007-10-25 : 03:40:20
|
| I have a table Customer with 200000 records.When I run queryDECLARE @posTable TABLE(idkey INT IDENTITY(1,1), value VARCHAR(128))INSERT INTO @posTable (value) SELECT CustID FROM Customer ORDER BY CustIDAt the first time it takes 1 minute 42 seconds, at the second time it only takes 3 seconds.When i run the query SELECT IDENTITY(INT, 1, 1) AS idkey, CustID INTO #posTable FROM Customer ORDER BY CustIDThe order in column idkey is not exactsPls. tell me why? and How can i rewrite it. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-25 : 03:44:04
|
Can you reproduce the problem with, say 20 customers? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
newprog
Starting Member
5 Posts |
Posted - 2007-10-25 : 03:53:16
|
| With 20 customers it only takes less than 1 second in two cases.Thanks for your quick reply. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-25 : 03:57:03
|
Thanks.Do you still have the problem with idkey with only 20 customers? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
newprog
Starting Member
5 Posts |
Posted - 2007-10-25 : 04:02:57
|
| With only 20 customers, It's No Problem. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-25 : 04:17:38
|
When do it become a problem?Try again with 2000 customers. Then 5000, 10000, 20000 and so on... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
newprog
Starting Member
5 Posts |
Posted - 2007-10-25 : 04:47:52
|
| When I try with 200, 500, 1000, 5000, 10000... CustomersResults:Records Run at Fisrt Time (Senconds) Run at Sencond Time (Senconds)200 0 0500 1 01000 3 05000 7 110000 16 220000 20 250000 47 2100000 65 3I dont Know Why, but the Proplem has occurs when run query at the fist time . |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-25 : 05:13:27
|
Are you sure you included the ORDER BY statement then? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
newprog
Starting Member
5 Posts |
Posted - 2007-10-25 : 05:21:27
|
| Yes, I'm sure |
 |
|
|
|