Rowid is virtual column in sqlite. when we create table, the rowid is created automatically as virtual column in that table.

Rowid will generate unique number to row. Say for example, we have mobile sales table.


select mobile_name,price,rowid from mobile_sales_details

mobile_name             price       rowid     
----------------------  ----------  ----------
Moto X (16 GB) (Black)  23999       1         
Moto G (Black  with 16  13999       2         
Moto E (Black)          6999        3         
Asus Zenfone 4 A400CG   5999        4         
Asus Zenfone 5 A501CG   9999        5         
Asus Zenfone 5 A501CG   12999       6         
Asus Zenfone 6 A600CG   16999       7         
Alcatel Onetouch Idol   16999       8         
Samsung Galaxy S Duos   8206        9         
Samsung Galaxy Star Pr  7599        10 

........
etc...

Actually ,in the above query, the table dont have any column which names as rowid,which is automatically created when creating the mobile sales table.

How to create a table without rowid

Syntax:


CREATE TABLE IF NOT EXISTS wordcount(
  word TEXT PRIMARY KEY,
  cnt INTEGER
) WITHOUT ROWID;

 

Points to remember while creating WITHOUT ROWID

 

1. Every WITHOUT ROWID table must have a PRIMARY KEY. An attempt to create a WITHOUT ROWID table without a PRIMARY KEY results in an error.

2. AUTOINCREMENT does not work on WITHOUT ROWID tables.

3. NOT NULL is enforced on every column of the PRIMARY KEY in a WITHOUT ROWID table.

 

Benefits Of WITHOUT ROWID Tables

 

1. A WITHOUT ROWID table is an optimization that can reduce storage and processing requirements.

The only advantage of a WITHOUT ROWID table is that it can sometimes use less disk space and/or perform a little faster than an ordinary rowid table.