Home > database >  The ORDER BY Time
The ORDER BY Time

Time:10-13

If I have two records database time field are equal, two records hypothesis is A, B

That when I select the order by the time field

Selected a table

The order of the table A, B each time is fixed, or A, B sequence of random exchange?

CodePudding user response:

There is an index or heap? Is a heap in written order, not according to the index

CodePudding user response:

E.g.
 USE Test 
GO
The CREATE TABLE T1 (INT A, B, INT);
INSERT INTO T1 VALUES (1, 1), (2, 2), (1, 1)
SELECT * FROM dbo. T1
/*
A, B
1 1
2 2
1 1
*/
The CREATE INDEX IX_T1 ON dbo. T1 (A, B);
SELECT * FROM dbo. T1
/*
A, B
1 1
1 1
2 2
*/

CodePudding user response:

For querying t-sql when no cover index with clustered index or heap

CodePudding user response:

For not only the sort field, it is suggested that increasing primary key sort together, every time to ensure that the positioning of the query,

For users to view page, this makes sense,

CodePudding user response:

If there are no use the order by the only key, then the result must be random, may you 10000 times, in the development environment, found that the order is the same, but to the production environment to run a certain period of time, can appear inconsistent situation,

The reason for this is to use different index, can affect the display,

CodePudding user response:

reference 4 floor gypsy song response:
for not only sort field, suggested adding a primary key with sorting, every time to ensure that the positioning of the query,

For users to view page, this makes sense,

+ 1
  • Related