Issue working with temporary table

守給你的承諾、 提交于 2019-12-14 03:54:01

问题


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);

The table is successfully created.

Then I enter the following statement also into phpMyAdmin:

INSERT INTO test_table
 (item1, item2, item3, item4)
 VALUES
 ('lentils', 99.00, 82, 8);

And I receive; "#1146 - Table 'mydatabase.test_table' doesn't exist" Any clues as to what is wrong here?


回答1:


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.

What is the reason for this?

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.




回答2:


I've been searching for some answers for your problem, and apparently, It's some sort of bug.

You need to drop your table,restart your MySQL service and re-build the table.

OR

You could rename the table.

(This fixed it for many others.)

Sources:

Bug? #1146 - Table 'xxx.xxxxx' doesn't exist

SQL - AS - table doesn't exist - 1146

http://bytes.com/topic/mysql/answers/706253-table-doesnt-exist-but-im-sure-does

http://mysql-tools.com/articles/mysql/48-table-mysqlproc-doesnt-exist.html

http://ubuntuforums.org/showthread.php?t=2095602

Edit:

It could possibly be that your MySQL Version is 'Outdated'. Try updating.

If your DB is inside PhpMyAdmin,use phpMyAdmin to import "create_tables.sql" from the examples folder of phpMyAdmin SRC: Source - Table-Doesn't-Exist



来源:https://stackoverflow.com/questions/20745555/issue-working-with-temporary-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!