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

Friday, 16 February 2024

Create Temp table in TERADATA

In Teradata, you can create Volatile Tables, which serve a similar purpose to temporary tables in other database systems. Volatile Tables are session-specific, meaning they are only visible to the session that creates them, and their data is automatically deleted when the session ends.

Here's the syntax for creating a Volatile Table in Teradata:

CREATE VOLATILE TABLE table_name (

    column1 datatype1,

    column2 datatype2,

    ...

);

- table_name: This is the name of the Volatile Table you want to create.

- column1, column2, etc.: These are the columns of the Volatile Table.

- datatype1, datatype2, etc.: These are the data types of the columns.

Here's an example of creating a Volatile Table in Teradata:

CREATE VOLATILE TABLE temp_employee (

    emp_id INTEGER,

    emp_name VARCHAR(100),

    emp_salary DECIMAL(10,2)

) ON COMMIT PRESERVE ROWS;

In this example:

- We create a Volatile Table named temp_employee with three columns: emp_id, emp_name, and emp_salary.

- The data type of emp_id is INTEGER, and the data types of emp_name and emp_salary are VARCHAR and DECIMAL, respectively.

- We specify ON COMMIT PRESERVE ROWS, meaning that the data in the Volatile Table will be retained at the end of the transaction.

After creating the Volatile Table, you can use it like a regular table within your session. However, keep in mind that the data in the Volatile Table is only visible within the session that created it, and it will be automatically deleted when the session ends or when explicitly dropped.

No comments:

Post a Comment

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