Android Code Snippet SQLITE automatic primary key generation

If you are sure you want to use artificial primary keys in a table you might want to have a way to generate those as a GUID automatically with every INSERT.

Just set (lower(hex(randomblob(16)))) as the default value.

B4X:
CREATE TABLE [mylookuptable](
  [id] GUID DEFAULT (lower(hex(randomblob(16)))),
  [vname] CHAR DEFAULT '>');

Keep in mind, it is pseudo random so uniqueness is not guaranteed.

- SQLite Randomblob is explained here

- Arguments pro/contra artificial keys mentioned here
 
Top