- Obtaining & Using MySQLi Metadata
- MySQLi - Handling NULL Values
- MySQLi - Using Joins
- MySQLi - Sorting Results
- MySQLi - Like Clause
- MySQLi - Delete Query
- MySQLi - Update Query
- MySQLi - Where Clause
- MySQLi - Select Query
- MySQLi - Insert Query
- MySQLi - Drop Tables
- MySQLi - Create Tables
- MySQLi - Select Database
- MySQLi - Drop Database
- MySQLi - Create Database
- MySQLi - Connection
- MySQLi - PHP Syntax
- MySQLi - Introduction
- MySQLi - Home
MySQL
- MySQL - Handling Duplicates
- MySQL - Using Sequences
- MySQL - Clone Tables
- MySQL - Temporary Tables
- MySQL - Indexes
- MySQL - Alter Command
- MySQL - Transactions
- MySQL - Regexps
- MySQL - Data Types
- MySQL - Administration
- MySQL - Installation
MySQLi Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MySQLi - Temporary Tables
The temporary tables could be very useful in some cases to keep temporary data. The most important thing that should be known for temporary tables is that they will be deleted when the current cpent session terminates.
As stated earper, temporary tables will only last as long as the session is apve. If you run the code in a PHP script, the temporary table will be destroyed automatically when the script finishes executing. If you are connected to the MySQL database server through the MySQL cpent program, then the temporary table will exist until you close the cpent or manually destroy the table.
Example
Here is an example showing you usage of temporary table. Same code can be used in PHP scripts using mysqp_query() function.
mysql> CREATE TEMPORARY TABLE SalesSummary ( → product_name VARCHAR(50) NOT NULL → , total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00 → , avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00 → , total_units_sold INT UNSIGNED NOT NULL DEFAULT 0 → ); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO SalesSummary → (product_name, total_sales, avg_unit_price, total_units_sold) → VALUES → ( cucumber , 100.25, 90, 2); mysql> SELECT * FROM SalesSummary; +--------------+-------------+----------------+------------------+ | product_name | total_sales | avg_unit_price | total_units_sold | +--------------+-------------+----------------+------------------+ | cucumber | 100.25 | 90.00 | 2 | +--------------+-------------+----------------+------------------+ 1 row in set (0.00 sec)
When you issue a SHOW TABLES command, then your temporary table would not be psted out in the pst. Now, if you will log out of the MySQL session and then you will issue a SELECT command, then you will find no data available in the database. Even your temporary table would also not exist.
Dropping Temporary Tables
By default, all the temporary tables are deleted by MySQL when your database connection gets terminated. Still if you want to delete them in between, then you do so by issuing DROP TABLE command.
Following is the example on dropping a temporary table −
mysql> DROP TABLE SalesSummary; mysql> SELECT * FROM SalesSummary; ERROR 1146: Table TUTORIALS.SalesSummary doesn t existAdvertisements