25

I have created a table in sqlite. There are two fields: pk_categoryid,category_name. I want to enter only one value from the user side. So, how can I create a sequence?

Wayne
  • 59,728
  • 15
  • 131
  • 126
Nidhi
  • 755
  • 3
  • 11
  • 25
  • See [this answer](https://stackoverflow.com/a/69088585/1070129) for how to create a sequence for a non-primary key field in SQLite. – emkey08 Sep 07 '21 at 13:05

3 Answers3

19

If you mean that you want the primary key to be autogenerated, then look at AUTOINCREMENT when creating your table:

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • 2
    If you don't care that deleted primary keys may be reused for subsequent rows, then you don't need the AUTOINCREMENT keyword (you can just do `pk_categoryid integer primary key`). [Using AUTOINCREMENT prevents id reuse but with an algorithm that has more overhead](https://sqlite.org/autoinc.html) – justincc Dec 31 '17 at 13:38
9
create table Categories (
    pk_categoryid integer primary key autoincrement, 
    category_name text
);
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
My Other Me
  • 5,007
  • 6
  • 41
  • 48
0
CREATE TABLE categories
(
    pk_categoryid INTEGER PRIMARY KEY AUTOINCREMENT, 
    category_name TEST
);

INSERT INTO categories (category_name) VALUES (//your value);
Xbox One
  • 307
  • 2
  • 13