{"id":8152,"date":"2020-04-06T08:31:10","date_gmt":"2020-04-05T22:31:10","guid":{"rendered":"https:\/\/database.guide\/?p=8152"},"modified":"2025-11-15T10:18:43","modified_gmt":"2025-11-15T00:18:43","slug":"create-temporary-table-sqlite","status":"publish","type":"post","link":"https:\/\/database.guide\/create-temporary-table-sqlite\/","title":{"rendered":"Create a Temporary Table in SQLite"},"content":{"rendered":"\n<p class=\"\">When you create a table in <a href=\"https:\/\/database.guide\/what-is-sqlite\/\">SQLite<\/a>, you can create it as a permanent table or as a <a href=\"https:\/\/database.guide\/what-is-a-temp-table\/\" data-type=\"post\" data-id=\"46127\">temporary table<\/a>.<\/p>\n\n\n\n<p class=\"\">When you create a table in a database that you&#8217;ve created, that would be a permanent table. A temporary table is created in the <code>temp<\/code> database.<\/p>\n\n\n\n<p class=\"\">To create a temporary table, you use the same syntax as <a href=\"https:\/\/database.guide\/create-table-sqlite\/\" class=\"aioseop-link\">creating a regular table<\/a>. The difference is that you use either the <code>TEMP<\/code> or <code>TEMPORARY<\/code> keyword. You can also (or alternatively) prefix the table name with <code>temp<\/code>, which indicates that it will be created in the temporary database.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"\">When using the <code>TEMP<\/code> or <code>TEMPORARY<\/code> keywords, you need to insert them between the <code>CREATE<\/code> and <code>TABLE<\/code>. <\/p>\n\n\n\n<p class=\"\">Like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMP TABLE Products(\n  ProductId, \n  ProductName,\n  Price\n);<\/code><\/pre>\n\n\n\n<p class=\"\">Or:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMPORARY TABLE Products(\n  ProductId, \n  ProductName,\n  Price\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add a Schema Name<\/h2>\n\n\n\n<p class=\"\">The only schema name you can use when doing this is <code>temp<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMP TABLE temp.Products(\n  ProductId, \n  ProductName,\n  Price\n);<\/code><\/pre>\n\n\n\n<p class=\"\">Or:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMPORARY TABLE temp.Products(\n  ProductId, \n  ProductName,\n  Price\n);<\/code><\/pre>\n\n\n\n<p class=\"\">However, if you specify the <code>temp<\/code> schema, you can omit the <code>TEMP<\/code> and <code>TEMPORARY<\/code> keywords altogether.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE temp.Products(\n  ProductId, \n  ProductName,\n  Price\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Check the Table<\/h2>\n\n\n\n<p class=\"\">As with any table, you can use <code>.table<\/code> to check that your temporary table has been created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.table<\/code><\/pre>\n\n\n\n<p class=\"\">Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">temp.Products<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 &#8230; <a title=\"Create a Temporary Table in SQLite\" class=\"read-more\" href=\"https:\/\/database.guide\/create-temporary-table-sqlite\/\" aria-label=\"Read more about Create a Temporary Table in SQLite\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,100],"tags":[9],"class_list":["post-8152","post","type-post","status-publish","format-standard","hentry","category-sql","category-sqlite","tag-create-table"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/8152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=8152"}],"version-history":[{"count":4,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/8152\/revisions"}],"predecessor-version":[{"id":46189,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/8152\/revisions\/46189"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=8152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=8152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=8152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}