database - SQlite foreign key logic -


i using sqlite , pk column seems auto-incrementing. bit concerned following approach want normalize type-column:

table: book id   type  name ...  ...   ... 15    1     foo 16    2     bar ...   ...  ...   table: type id  typename 1   magazine 2   novel 

what happens, if recreate type-table , pk-index (="id") changes, e.g. 1 refers novel instead of magazine. more robust, thinking inserting custom second column contains "logical" indices refer to:

table: book id   type  name 1    3     foo 2    4     bar  table: type id   type  typename 1    3     magazine 2    4     novel 

this way custom type-ids independent primary keys. think advantage of last approach not have re-ask latest (new) id of new row, because refer type column know before. way when insert row know "type" id make references (i using threads database, reading value database within method difficult or not possible (?) - if need id, have ask db first).

is legit approach? or should directly create non-incrementing primary key "custom id's" manage on own?

as shown in documentation, can insert desired values in pk column:

insert type(id, typename) values(2, 'novel') 

and if never need autoincrement values, should not use autoincrementing column in first place.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -