问题描述
我在phpMyAdmin中输入以下内容:
I enter the following into phpMyAdmin:
CREATE TEMPORARY TABLE test_table (
item1 VARCHAR(50) NOT NULL
, item2 DECIMAL(12,2) NOT NULL DEFAULT 0.00
, item3 DECIMAL(7,2) NOT NULL DEFAULT 0.00
, item4 INT UNSIGNED NOT NULL DEFAULT 0);
表已成功创建.
然后我也在phpMyAdmin中输入以下语句:
Then I enter the following statement also into phpMyAdmin:
INSERT INTO test_table
(item1, item2, item3, item4)
VALUES
('lentils', 99.00, 82, 8);
我收到了; #1146-表'mydatabase.test_table'不存在"关于这里出了什么问题的任何线索吗?
And I receive; "#1146 - Table 'mydatabase.test_table' doesn't exist"Any clues as to what is wrong here?
推荐答案
临时表仅适用于当前的PhpMyAdmin查询,因为一旦执行查询,它将关闭您的数据库会话.如果您分别执行这两个查询,则将收到此错误,因为在第一个查询执行完毕后,MySQL数据库将立即删除临时表.
Temporary tables only exist for the current PhpMyAdmin query as it closes your DB session once the query has been executed. If you are executing these two queries separately then you will get this error as the MySQL database will drop the temporary table right after the first query has finished executing.
这是什么原因?
原因是您可以创建创建这些临时表的函数或过程而不会阻塞数据库,因为一旦函数或过程执行完毕,它们将被自动删除.
The reason is so you can create functions or procedures that create these temporary tables without clogging up your database as they will be automatically removed once the function or procedure has finished its execution.
解决方案是在一个查询中执行所有操作,或者仅使用普通表.
The solution would be to execute everything in one query or just use a normal table.
这篇关于使用临时表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!