首页 > 解决方案 > 插入临时表mysql

问题描述

select t.* 
into #temp 
from 
( 
select 'a' as a 
union all 
select 'b' as a 
) as t 

select * from #temp 

drop table #temp 

我通常在创建临时表的 SQL 服务器上执行此操作。语法“into #temp”在数据库上创建一个非物理表,而“into temp”将在数据库上创建一个物理表。

我在 MySQL 中的问题是转换上面的 MSSQL 语句。我想要创建的是一个不在数据库上物理创建的临时表。我们在 MySQL 中有这个功能吗?

标签: mysqlsql-serverinserttemp-tables

解决方案


在 MySQL 中,您将使用create temporary table as

create temporary table temp as
    select 'a' as a 
    union all 
    select 'b' as a ;

推荐阅读