USE TempDB
GO
CREATE TABLE OrderTest(N1 INT NOT NULL, C1 VARCHAR(100) NOT NULL)
GO
INSERT INTO OrderTest(N1, C1) VALUES(1, 'First Insert')
GO
INSERT INTO OrderTest(N1, C1) VALUES(10, 'Second Insert')
GO
INSERT INTO OrderTest(N1, C1) VALUES(2, 'Third Insert')
GO
INSERT INTO OrderTest(N1, C1) VALUES(4, 'Fourth Insert')
GO
USE TempDB
GO
SELECT * FROM OrderTest
GO
The results are indeed retrieved in the order in which it is inserted. Convinced?
USE TempDB
GO
ALTER TABLE OrderTest ADD PRIMARY KEY(N1)
GO
USE TempDB
GO
SELECT * FROM OrderTest
GO
The rows are NOT returned in the order in which it is inserted!! Surprising??
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)