Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday, 25 October 2014

Creating Global Temporary Table in Teradata

When you need to perform some DML (Data Manipulation Language) operation and then want to delete all the data from the table but don't want to DROP the table as you may require it for next time to use, you can create GLOBAL TEMPORARY TABLE in teradata which delete all the data from the table when you log out from the session but keeps the definition of the table intact.

Let's see how we can create Global Temporary Table:-

CREATE GLOBAL TEMPORARY TABLE TABLE_NAME
(
COLUMN_NAME DATA_TYPE;
COLUMN_NAME DATA_TYPE;
COLUMN_NAME DATA_TYPE;
COLUMN_NAME DATA_TYPE;
.
.
)
 ON COMMIT PRESERVE ROWS;

Note:- When you are creating global temporary table and forget to mention ON COMMIT PRESERVE ROWS then you would not be able to see the data as teradata create global temporary table as ON COMMIT DELETE ROWS by default. So, work accordingly as per your requirement.

Please provide your feedback in the comments section above. Please don't forget to follow.