MySQL temporary table name is per connection, UNIQUE for each connection safely use it
2008-10-15 20:50
591 查看
I understand temporary tables are dropped automatically. But are the tables which are created unique? i.e. should I create a different name for the table or does mysql sort this out?
CREATE temporary table TEMP1 TYPE=HEAP select * from CUSTOMERS
.
.
PHP database report stuff here....
.
.
DROP temporary table TEMP1
This creates a temporary table called TEMP1 and is populated from CUSTOMERS.
1. What happens if 2 users run the code at near the same time? Will the TEMP1 table be corrupted?
2. What happens if 1 user fires up 2 browser windows and runs the script at near the same time?
3. Is it really necessary to DROP the table at the end of the code. mysql says that temporary tables are automatically dropped.
I could create a random name rather than TEMP1 that should sort it?
Note that the TYPE=HEAP doesn't really matter here. The same problem should exist if HEAP or not: does creating a temporary table create TEMP1 in seperate user space?
----------------------------------------------------------------------------------
Frank,
This is what I got from mysql docs:
"A temporary table will automatically be deleted if a connection dies and the name is per connection. This means that two different connections can both use the same temporary table name without conflicting with each other or with an existing table of the same name. (The existing table is hidden until the temporary table is deleted.)"
So this means you can safely use any name for your temporary table.
CREATE temporary table TEMP1 TYPE=HEAP select * from CUSTOMERS
.
.
PHP database report stuff here....
.
.
DROP temporary table TEMP1
This creates a temporary table called TEMP1 and is populated from CUSTOMERS.
1. What happens if 2 users run the code at near the same time? Will the TEMP1 table be corrupted?
2. What happens if 1 user fires up 2 browser windows and runs the script at near the same time?
3. Is it really necessary to DROP the table at the end of the code. mysql says that temporary tables are automatically dropped.
I could create a random name rather than TEMP1 that should sort it?
Note that the TYPE=HEAP doesn't really matter here. The same problem should exist if HEAP or not: does creating a temporary table create TEMP1 in seperate user space?
----------------------------------------------------------------------------------
Frank,
This is what I got from mysql docs:
"A temporary table will automatically be deleted if a connection dies and the name is per connection. This means that two different connections can both use the same temporary table name without conflicting with each other or with an existing table of the same name. (The existing table is hidden until the temporary table is deleted.)"
So this means you can safely use any name for your temporary table.
相关文章推荐
- Error 3724:Cannot drop the table 'object_name' because it is being used for replication.
- Mysql: Table name is specified twice, both as a target for UPDATE and as a separate source for data
- Error 3724:Cannot drop the table 'object_name' because it is being used for replication.-ZT
- mysql -- error code [1442]; Can't update table 'table_name' in stored function/trigger because it is already used by statement w
- mysql报Table 'XXX' is specified twice, both as a target for 'UPDATE'....
- mysql 触发器的问题 Can't update table 'tbl' in stored function/trigger because it is already used by state
- Error response from daemon: Conflict. The container name "/mysql" is already in use by container
- error C4996 The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
- 删除数据库时提示数据库正在被使用,无法删除(Cannot drop database databasename because it is currently in use)的问题
- max tablename length limit in MySQL is 64
- mysql 报错:Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65
- sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database
- mysql: "tablename" is marked as crashed and should be repaired修复 问题分析: 当mysql出现这类提示时,大部分的现象为查询不到正常的
- mysql (create temporary table table_name )临时表创建
- Cannot drop database "databasename" because it is currently in use.
- MySpace Unraveled: What it is and how to use it safely
- error C4996: 'getpid': The POSIX name for this item is deprecated. Instead, use the ISO C++ conforma
- MySQL: [ERROR] /usr/sbin/mysqld: Incorrect key file for table './xxx/xxxx.MYI'; try to repair it
- 在使用visual studio 2013写程序时 ,出现了(“The POSIX name for this item is deprecated. Instead, use the ISO C+
- 删除数据库时提示数据库正在被使用,无法删除(Cannot drop database databasename because it is currently in use)的问题