We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

First of all let's see why one should use Temporary table.
 
  • It is faster to get data from temporary table instead of getting data form DB tables with several filter conditions.
  • Temporary tables are connection specific. When the current client session terminates all the temporary tables are automatically deleted.
  • Temporary table with same name can be created with in different connections.
 
Here is the syntax to create temporary table by getting data from another table with in a stored procedure.
 
SET @TEMPQUERY = 'CREATE TEMPORARY TABLE TEMP_EMP_TABLE';
SET @TEMPQUERY = CONCAT (@TEMPQUERY, ' AS SELECT EMP_ID, EMP_NAME, EMP_ADDRS, EMP_PHONE FROM EMPLOYEE ');
SET @TEMPQUERY = CONCAT (@TEMPQUERY, ' WHERE EMP_ID IN (SELECT EMP_ID FROM EMP_COMPANY)');
 
PREPARE MYSQLQUERY FROM @TEMPQUERY;
EXECUTE MYSQLQUERY;


Related Tags:

Database, MySQL

Author: Rashmita Devi

top

Database

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login