mysql中的臨時表

2021-03-31 08:56:29 字數 654 閱讀 9442

建立臨時表很容易,給正常的create table語句加上temporary關鍵字:

create temporary table tmp_table (

name varchar(10) not null,

value integer not null

)臨時表將在你連線mysql期間存在。當你斷開時,mysql將自動刪除表並釋放所用的空間。當然你可以在仍然連線的時候刪除表並釋放空間。

drop table tmp_table

如果在你建立名為tmp_table臨時表時名為tmp_table的表在資料庫中已經存在,臨時表將有必要遮蔽(隱藏)非臨時表tmp_table。

如果你宣告臨時表是乙個heap表,mysql也允許你指定在記憶體中建立它:

create temporary table tmp_table (

name varchar(10) not null,

value integer not null

) type = heap

因為heap表儲存在記憶體中,你對它執行的查詢可能比磁碟上的臨時表快些。然而,heap表與一般的表有些不同,且有自身的限制。詳見mysql參考手冊。

正如前面的建議,你應該測試臨時表看看它們是否真的比對大量資料庫執行查詢快。如果資料很好地索引,臨時表可能一點不快。

mysql臨時表更新 MySql 臨時表

今天在專案中遇到乙個,當mysql的in語句中資料量很大時,建立乙個臨時表的例子。於是樓主整理了一下關於臨時表的知識,與大家分享一下 首先,臨時表只在當前連線可見,當關閉連線時,mysql會自動刪除表並釋放所有空間。因此在不同的連線中可以建立同名的臨時表,並且操作屬於本連線的臨時表。建立臨時表 cr...

mysql 臨時表 限制 Mysql臨時表

當你建立臨時表的時候,你可以使用temporary關鍵字。如 create temporary table tmp table name varchar 10 not null,passwd char 6 not null 或create temporary table if not exists ...

mysql 臨時表 漢字 mysql的臨時表用法

delimiter use qgroupdata drop procedure if exists ex print bg kdd search create definer root procedure ex print bg kdd search where varchar 2000 查詢條件 ...