Application Service Guide > Data Integration Service Management > Persisting Virtual Data in Temporary Tables
  

Persisting Virtual Data in Temporary Tables

A temporary table is a table in a relational database that stores intermediate, temporary data. Complex queries commonly require storage for large amounts of intermediate data, such as information from joins. When you implement temporary tables, business intelligence tools can retrieve this data from the temporary table instead of the SQL data service. This results in an increase in performance.
Temporary tables also provide increased security in two ways. First, only the user of the active session can access the tables. Also, the tables persist while a session is active, and the database drops the tables when the connection closes.
You must configure the Table Storage Connection property of the Data Integration Service before the database administrator creates a temporary table.
Temporary tables for all SQL data services in a Data Integration Service use the same relational database connection. When the connection to the SQL data service is active, you can connect to the SQL data service through a JDBC or ODBC client. The relational database drops temporary tables when the session ends. If the Data Integration Service unexpectedly shuts down, the relational database drops temporary tables on the next Data Integration Service startup.

Temporary Table Implementation

You can store intermediate query result set data in temporary tables when complex queries produce large amounts of intermediate data. For example, temporary tables can store frequently used join results. Business intelligence tools can query the temporary table instead of the SQL data service, resulting in increased performance.
To implement temporary tables, the Informatica administrator and the business intelligence tool user perform the following separate tasks:
Step 1. The Informatica administrator creates a connection for the data integration service.
In the Administrator tool, create a connection to the SQL data service. Edit the SQL Properties of the Data Integration Service and select a relational database connection for the Table Storage Connection property. Recycle the Data Information Service.
Step 2. The business intelligence tool user creates a connection for the SQL data service.
In a business intelligence tool, create a connection to the SQL data service. The connection uses the Informatica ODBC or JDBC driver.
Step 3. Queries from the business intelligence tool create and use temporary tables.
While the connection is active, the business intelligence tool issues queries to the SQL data service. These queries create and use temporary tables to store large amounts of data that the complex query produces. When the connection ends, the database drops the temporary table.

Temporary Table Operations

After you create the SQL data service connection, you can use SQL operations to create, populate, select from, or drop a temporary table. You can issue these commands in a regular or stored SQL statement.
You can perform the following operations:
Create a temporary table.
To create a temporary table on the relational database, use the following syntax:
CREATE TABLE emp (empID INTEGER PRIMARY KEY,eName char(50) NOT NULL,)
You can specify the table name in the SQL data service.
Note: Use CREATE TABLE, not CREATE TEMPORARY TABLE. The use of CREATE TEMPORARY TABLE is not supported.
Create a temporary table from a source table.
You can create a temporary table with or without data from a source table.
The following syntax is supported in Informatica Data Services version 9.5.1:
CREATE TABLE emp.backup as select * from emp
Where emp is an existing schema in the SQL data service that you connected to.
The following syntax is supported in Informatica Data Services version 9.6.0 and 9.6.1:
CREATE TABLE emp.backup as select * from emp [ [LIMIT n] ]
Where emp is an existing schema in the SQL data service that you connected to.
When you create a temporary table with data, the Data Integration Service populates the table with the data. The CREATE AS operator copies columns from a database table into the temporary table.
You cannot maintain foreign key or primary key constraints when you use CREATE AS.
You can cancel a request before the Data Integration Service copies all the data.
Note: The Informatica administrator must create a connection, and then configure it in SQL Properties as the Table Storage Connection, before you create the temporary table.
Insert data into a temporary table.
To insert data into a temporary table, use the INSERT INTO <temp_table> statement. You can insert literal data and query data into a temporary table.
The following table shows examples of SQL statements that you can use to insert literal data and query data into a temporary table:
Type
Description
Literal data
Literals describe a user or system-supplied string or value that is not an identifier or keyword. Use strings, numbers, dates, or boolean values when you insert literal data into a temporary table. Use the following statement format to insert literal data into a temporary table:
INSERT INTO <TABLENAME> <OPTIONAL COLUMN LIST> VALUES (<VALUE LIST>), (<VALUE LIST>)
For example, INSERT INTO temp_dept (dept_id, dept_name, location) VALUES (2, 'Marketing', 'Los Angeles').
Query data
You can query an SQL data service and insert data from the query into a temporary table. Use the following statement format to insert query data into a temporary table:
INSERT INTO <TABLENAME> <OPTIONAL COLUMN LIST> <SELECT QUERY>
For example, INSERT INTO temp_dept(dept_id, dept_name, location) SELECT dept_id, dept_name, location from dept where dept_id = 99.
You can use a set operator, such as UNION, in the SQL statement when you insert query data into a temporary table. Use the following statement format when you use a set operator:
INSERT INTO <TABLENAME> <OPTIONAL COLUMN LIST> (<SELECT QUERY> <SET OPERATOR> <SELECT QUERY>)
For example, INSERT INTO temp_dept select * from north_america_dept UNION select * from asia_dept.
Select from a temporary table.
You can query the temporary table with the SELECT ... from <table> statement.
Drop a temporary table.
To drop a temporary table from the relational database, use the following syntax:
DROP TABLE <tableName>
If the table is not dropped on the physical database, the SQL data service drops the table the next time the Data Integration Service starts, if the table still exists.

Rules and Guidelines for Temporary Tables

Consider the following rules and guidelines for creation and use of temporary tables: