Clustered vs NonClustered Primary Key

clustered-index, performance, sqlite

Solution

A great answer to this question is available over at the DBA StackExchange: https://dba.stackexchange.com/questions/7741/when-should-a-primary-key-be-declared-non-clustered/7744#7744

Problem

``` begin transaction; create table person_id(person_id integer primary key); insert into person_id values(1); ... snip ... insert into person_id values(50000); commit; ``` This code takes about 0.9 seconds on my machine and creates a db file taking up 392K. These numbers become 1.4 seconds and 864K if I change the second line to ``` create table person_id(person_id integer nonclustered primary key); ``` Why is this the case?

Original source