0

I've got a table in SQLite

create table table_dishes (_id integer primary key autoincrement, 
    title text,
    price real,
    weight real,
    description text,
    position integer);

How to make field "position integer" autoincrement?

3 Answers3

1

There is as such no autoincrement feature but they have added ROWID which is added automatically. So the integer primary key which you will create for your table will point to this ROWID.

Also from the SQLITE docs:

A column declared INTEGER PRIMARY KEY will autoincrement.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

Per the SQLite documentation here,

Short answer: A column declared INTEGER PRIMARY KEY will autoincrement

Alexander Lucas
  • 22,171
  • 3
  • 46
  • 43
0

insert value should be like : (SELECT IFNULL(MAX(position), 0) + 1 FROM table_dishes) for that column, every time you insert a new row into table_dishes table, if you decide to keep position column as non-primary key

user3487063
  • 3,672
  • 1
  • 17
  • 24