
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Create a temporary table in a MySQL procedure?
To create a temporary table in a MySQL procedure, following is the syntax −
CREATE PROCEDURE yourProcedureName() BEGIN CREATE TEMPORARY TABLE yourTemporaryTableName SELECT yourValue; END
Let us implement the above syntax to create a temporary table and insert some records in the table. Following is the query to create a stored procedure and a temporary table in it −
mysql> DELIMITER // mysql> CREATE PROCEDURE create_Temporary_Table() -> BEGIN -> CREATE TEMPORARY TABLE tmpDemoTable SELECT 500; -> END// Query OK, 0 rows affected (0.15 sec)
Following is the query to insert record in the table −
mysql> CREATE PROCEDURE insert_Record_InTempTable() -> BEGIN -> INSERT INTO tmpDemoTable VALUES (300); -> END// Query OK, 0 rows affected (0.06 sec)
mysql> DELIMITER
Now you can call the above stored procedure to create a temporary table −
mysql> call create_Temporary_Table(); Query OK, 1 row affected (0.00 sec) mysql> call insert_Record_InTempTable(); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select *from tmpDemoTable;
Output
This will produce the following output −
+-----+ | 500 | +-----+ | 500 | | 300 | +-----+ 2 rows in set (0.00 sec)
- Related Articles
- Create a temporary table with dates in MySQL
- MySQL Stored Procedure to create a table?
- How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?
- Create a temporary table similar to a regular table with MySQL LIKE
- Create a table inside a MySQL stored procedure and insert a record on calling the procedure
- How can we create a MySQL temporary table by using PHP script?
- How can I create a stored procedure to insert values in a MySQL table?
- How can I create a stored procedure to update values in a MySQL table?
- MySQL stored procedure to execute SHOW CREATE TABLE?
- Create a procedure in MySQL with parameters?
- How can I create a MySQL stored procedure that returns multiple values from a MySQL table?
- How can I create a stored procedure to delete values from a MySQL table?
- Create a stored procedure to get the detail of a particular MySQL table stored in a database?
- Insert data in a table in MySQL stored procedure?
- Create a stored procedure with delimiter in MySQL

Advertisements