【问题标题】:Insert into temporary table mysql插入临时表mysql
【发布时间】:2018-11-20 16:19:51
【问题描述】:
select t.* 
into #temp 
from 
( 
select 'a' as a 
union all 
select 'b' as a 
) as t 

select * from #temp 

drop table #temp 

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

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

【问题讨论】:

    标签: mysql sql-server insert temp-tables


    【解决方案1】:

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

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

    【讨论】:

    • 它的范围仅限于会话?
    • 而且MySQL也有DROP TEMPORARY TABLE table删除临时表。
    • "创建表时可以使用 TEMPORARY 关键字。TEMPORARY 表仅在当前会话中可见,并在会话关闭时自动删除。这意味着两个不同的会话可以使用相同的临时表名,不会相互冲突或与现有的同名非临时表冲突。" @RamSingh source dev.mysql.com/doc/refman/8.0/en/create-temporary-table.html
    猜你喜欢
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2011-11-14
    • 1970-01-01
    • 2012-09-29
    • 2016-07-22
    相关资源
    最近更新 更多