RB Smissaert wrote:
Is there any difference in an index created like this:

Create table 'table1'([ID] INTEGER PRIMARY KEY)

with this:

Create table 'table1'([ID] INTEGER)

Create unique index idx_table1_ID on table1(ID)

I tended to use the first form, but as that can make subsequent table
inserts or deletes slower I am now moving to the second form.

Yes there is. The first uses the key for the btree that stores the table to hold the id. The second uses a second comlpetely independent btree to store an index that holds records that contain the id number and the rowid of the corresponding record in the table. The table itself contains a rowid as the key of the table btree and the user id field.

SQLite version 3.3.13
Enter ".help" for instructions
sqlite> Create table 'table1'([ID] INTEGER PRIMARY KEY);
sqlite> select * from sqlite_master;
table|table1|table1|2|CREATE TABLE 'table1'([ID] INTEGER PRIMARY KEY)

SQLite version 3.3.13
Enter ".help" for instructions
sqlite> Create table 'table1'([ID] INTEGER);
sqlite> Create unique index idx_table1_ID on table1(ID);
sqlite> select * from sqlite_master;
table|table1|table1|2|CREATE TABLE 'table1'([ID] INTEGER)
index|idx_table1_ID|table1|3|CREATE UNIQUE INDEX idx_table1_ID on table1(ID)

The first version stores on integer for each record, and stores it in the btree key. The second stores four integers for each record, two in the table record and two in the index record. You are making your database much larger for no reason.

Also, you are using literal strings (delimited with a single quote) for your table names. This is not standard SQL and will not be portable. You are also using square brackets to quote your column names. This is also an SQLite and MS extension to standard SQL. You should quote identifiers such as table and column names with double quotes.

   Create table 'table1'([ID] INTEGER PRIMARY KEY)

should be:

   Create table "table1"("ID" INTEGER PRIMARY KEY)
HTH
Dennis Cote

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to