SQLite Forum

Without rowid
Login
In an idle moment today, I happened to be looking at the WITHOUT ROWID docs, and seeing an example of when one might use it in a database I have, did the following. The original schema was this, in the BEFORE database:

`create table info (token text primary key, ct1 integer, ct2 integer, ct3 integer);
CREATE TABLE counts  (  xtotal integer not null default 0,  ytotal integer not null default 0  );
CREATE TABLE globals (app_version integer, data_version integer default 0);`

I then created an AFTER database with the same schema, except that the info table was defined thus:

`create table info (token text primary key, ct1 integer, ct2 integer, ct3 integer) without rowid;`

I then copied the data from BEFORE to AFTER as follows, using the CLI:

`sqlite3 AFTER
SQLite version 3.28.0 2019-04-16 19:49:53
Enter ".help" for usage hints.
sqlite> attach BEFORE as sp;
sqlite> insert into main.info select * from sp.info;
sqlite> insert into main.counts select * from sp.counts;
sqlite> insert into main.globals select * from sp.globals;
sqlite> detach database sp;
sqlite3> ctrl-d`

I then exchanged the filenames so that my app would use the new database. Note that info has circa 170k rows, and the other two tables one row each. BEFORE is about 6.95Mbytes, AFTER is about 3.87Mbytes. So neither is large.

Is there any reason that BEFORE and AFTER might not be functionally identical?

First time I ran my app using AFTER, it appeared to go into a loop and I got "database locked" when trying to look at AFTER with the CLI. It appears happier now.