Creating Clustered Index on a NON-Primary Key Column, Will sort the values and store ONLY on Disk[ if VARCHAR then A-Z] and Not necessary to show them on query result set ?
Though the record inserted is not in order why query output always sorted based on primary key column [ not clustered]?
CREATE TABLE TEST ( N INTEGER NOT NULL, NAME VARCHAR(10)) CREATE CLUSTERED INDEX IDX_1 ON TEST(NAME) ALTER TABLE TEST ADD PRIMARY KEY (N) INSERT INTO TEST VALUES (2,'D'),(1,'C'),(4,'A'),(3,'B'),(100,'Z') SELECT * FROM TEST output: N NAME 1 C 2 D 3 B 4 A 100 Z I thought result set would return like this :
N NAME 4 A 3 B 1 C 2 D 100 Z
order by. You didn't use anorder byso the database is free to return the rows in any order it likes. If you need a specific sort order you have to useorder by. There is no alternative