An example on what ROWID is in SQLite

ROWID is of alias of an integer primary key:

CREATE TABLE test1(id INTEGER, b TEXT, PRIMARY KEY(id))
INSERT INTO test1 (id, b) VALUES (5, 'five');
INSERT INTO test1 (id, b) VALUES (6, 'six');
INSERT INTO test1 (b) VALUES ('seven');
SELECT rowid, * FROM test1;

the result is the following:

(5, 5, 'five')
(6, 6, 'six')
(7, 7, 'seven')
DELETE FROM test1 WHERE id = 6;
INSERT INTO test1 (b) VALUES ('eight');
(5, 5, 'five')
(7, 7, 'seven')
(8, 8, 'eight')

An example with composite primary key

CREATE TABLE t2(id INTEGER, a INTEGER, b TEXT, PRIMARY KEY(id, a));
INSERT INTO t2 (id, a, b) VALUES (5, 15, 'five');
(1, 5, 15, 'five')

2 Responses to An example on what ROWID is in SQLite

  1. dmitriano says:

    Primary key is not unique in SQLite
    https://stackoverflow.com/questions/79462083/primary-key-is-not-unique-in-sqlite

    Rightfully SQLite should not allow NULL as primary key value, but due to a bug it allows it

  2. dmitriano says:

    https://www.geeksforgeeks.org/mysql-unique-index/
    ALTER TABLE tbl_name
    DROP INDEX index_unique_columns;

    ALTER TABLE tbl_name
    ADD UNIQUE INDEX index_unique_columns (new_column1, new_column2, …);

Leave a Reply

Your email address will not be published. Required fields are marked *