I have additional question related to topic "The order of a SQL Select statement without Order By clause"
Let's assume we need to demonstrate that we must use Order By to return rows in specific order. So we want to show that SELECT returns rows in THE RANDOM order, or that INSERT inserts rows in random order, based on T-SQL
DECLARE @NotSortedTable TABLE(
ID INT NOT NULL,
C1 INT,
C2 FLOAT,
C3 DATETIME,
C4 VARCHAR(5)
)
INSERT INTO @NotSortedTable
VALUES (3, 3, 3.0, '26 oct 2018', 'Z'),
(2, 2, 2.0, '25 oct 2018', 'Y'),
(1, 1, 1.0, '24 oct 2018', 'X')
SELECT * FROM @NotSortedTable
What should I change in this SQL to make rows returned in WRONG order, not in the order how it was inserted into database.
Additional question:
When I do SELECT, it seems data ALWAYS returned in very specific order
ID C1 C2 C3 C4
3 3 3 2018-10-26 00:00:00.000 Z
2 2 2 2018-10-25 00:00:00.000 Y
1 1 1 2018-10-24 00:00:00.000 X
Where exactly this order defined in database? Is this some property, index or second on HDD? or something else?
Help appreciated