Create a Temporary Table in SQLite

When you create a table in SQLite, you can create it as a permanent table or as a temporary table.

When you create a table in a database that you’ve created, that would be a permanent table. A temporary table is created in the temp database.

To create a temporary table, you use the same syntax as creating a regular table. The difference is that you use either the TEMP or TEMPORARY keyword. You can also (or alternatively) prefix the table name with temp, which indicates that it will be created in the temporary database.

Example

When using the TEMP or TEMPORARY keywords, you need to insert them between the CREATE and TABLE.

Like this:

CREATE TEMP TABLE Products(
  ProductId, 
  ProductName,
  Price
);

Or:

CREATE TEMPORARY TABLE Products(
  ProductId, 
  ProductName,
  Price
);

Add a Schema Name

The only schema name you can use when doing this is temp.

CREATE TEMP TABLE temp.Products(
  ProductId, 
  ProductName,
  Price
);

Or:

CREATE TEMPORARY TABLE temp.Products(
  ProductId, 
  ProductName,
  Price
);

However, if you specify the temp schema, you can omit the TEMP and TEMPORARY keywords altogether.

CREATE TABLE temp.Products(
  ProductId, 
  ProductName,
  Price
);

Check the Table

As with any table, you can use .table to check that your temporary table has been created.

.table

Result:

temp.Products