我想在Laravel / Lumen中创建临时表,我制作了这样的模式。
Schema::create('temp_image', function (Blueprint $table) {
$table->increments('id');
$table->string('link');
$table->timestamps();
$table->temporary();
});
当我跑php artisan migrate
时,我看到......
Migrating: 2017_11_25_165640_create_temp_table
Migrated: 2017_11_25_165640_create_temp_table
...但它没有创建任何表格。发生了什么?
答案 0 :(得分:2)
Temporary tables
是基于会话的。它不是在SQL Server
上创建的。您可以查看 laracast 中的this文章。
临时表也可以在lumen
中使用。我们可以使用Schema Builder
到create
表和drop
表。
假设我们有一个简单请求的函数。我们可以使用temporary table
,如下所示 -
public function temporary_check()
{
Schema::create('temp_message', function (Blueprint $table) {
$table->increments('id');
$table->integer('sender_id');
$table->integer('receiver_id');
$table->string('message');
$table->timestamps();
$table->temporary();
});
DB::table('temp_message')->insert(['sender_id'=>2,'receiver_id'=>3,'message'=>'message temp check']);
$data = DB::table('temp_message')->get();
Schema::drop('temp_message');
return $data;
}
由于Temporary Table
基于session
,因此在您工作结束时,free-up
表格应始终memory
dropping
。
答案 1 :(得分:0)
临时表是一种特殊类型的表,允许您存储临时结果集,您可以在单个会话中多次重复使用。所以,如果你试图找到它们,你可能不会得到它,因为它们是基于会话的。
当会话结束或连接终止时, MySQL
会自动删除临时表。
您应该记住,这些表是在没有索引的情况下创建的,因此如果您的目标是提高查询速度,则通常需要在创建表后添加索引。
您可以阅读更多相关信息:http://www.mysqltutorial.org/mysql-temporary-table/