I want to create table in Teradata. Therefore I am using this syntax:
CREATE VOLATILE TABLE a AS
(
Select * FROM ...
) WITH DATA PRIMARY INDEX ( ACCOUNT_ID )
;
The inner SELECT statement results in 4 rows. However, when I run the entire query, the resulting data set does not have any rows. Strange, I know - that`s why I'm writing. Please help. Thanks.
CREATE VOLATILE TABLE GEEK ( ROLLNO INT, FIRST_NAME VARCHAR(15), LAST_NAME VARCHAR(15) ) PRIMARY INDEX (ROLLNO) ON COMMIT PRESERVE ROWS; Here, you can clearly see the last line written as ON COMMIT PRESERVE ROWS this line will preserve the data after inserting it by you. The default value is ON COMMIT DELETE ROWS.
Syntax: /* Volatile Table Syntax - Teradata */ CREATE VOLATILE TABLE table_1.
The ON COMMIT PRESERVE ROWS option provides the more normal situation where the table rows are kept after the end of the transaction. If the rows are going to be needed for other queries in other transactions.
Can I create a secondary index on a volatile table? This is possible when the table is created. Thus, you cannot first create the table and then execute a CREATE INDEX statement.
You need to include the ON COMMIT PRESERVE ROWS
option with your DDL for the volatile table:
CREATE VOLATILE TABLE a AS
(
Select * FROM ...
) WITH DATA
PRIMARY INDEX ( ACCOUNT_ID )
ON COMMIT PRESERVE ROWS;
The default COMMIT
mode for volatile (and global temporary) tables is to DELETE
the rows at the end of the transaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With