如何检查临时表的存在并在 sqlite3 中使用 INTO 语句创建它

问题描述

我从第一天开始就在 sql Server 中使用这个公式:

if object_id('tempdb..#t1') is not null drop table #t1;
select 
    column1,column2 
into #t1
from tab

我如何在 sqliteStudio 中实现它?

解决方法

您需要 2 条语句:

-- delete the temp table if it exists 
DROP TABLE IF EXISTS temp.t1;

-- create the temp table 
CREATE TEMPORARY TABLE temp.t1 AS
SELECT column1,column2
FROM tab;

参见enter image description here