插入临时表mysql

Ram*_*ngh 1 mysql sql-server insert temp-tables

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

select * from #temp 

drop table #temp 
Run Code Online (Sandbox Code Playgroud)

我通常在SQL服务器上执行此操作,其中我创建一个临时表.语法"into #temp"在DB上创建非物理表,而"into temp"将在DB上创建物理表.

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

Gor*_*off 6

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

create temporary table temp as
    select 'a' as a 
    union all 
    select 'b' as a ;
Run Code Online (Sandbox Code Playgroud)

  • "您可以在创建表时使用TEMPORARY关键字.TEMPORARY表仅在当前会话中可见,并在会话关闭时自动删除.这意味着两个不同的会话可以使用相同的临时表名称而不会与每个会话冲突其他或与现有的同名非TEMPORARY表."@ RamSingh source https://dev.mysql.com/doc/refman/8.0/en/create-temporary-table.html (2认同)