且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在没有单独的 CREATE TABLE 的 SELECT 语句中创建临时表

更新时间:2023-11-30 18:52:16

CREATE TEMPORARY TABLE IF NOT EXISTS table2 AS (SELECT * FROM table1)

来自 http://dev.mysql 的手册.com/doc/refman/5.7/en/create-table.html

您可以在创建表时使用 TEMPORARY 关键字.TEMPORARY 表仅对当前会话可见,并在会话关闭时自动删除.这意味着两个不同的会话可以使用相同的临时表名称,而不会相互冲突或与现有的同名非临时表发生冲突.(在删除临时表之前,现有表是隐藏的.)要创建临时表,您必须具有 CREATE TEMPORARY TABLES 权限.

You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current session, and is dropped automatically when the session is closed. This means that two different sessions can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.) To create temporary tables, you must have the CREATE TEMPORARY TABLES privilege.