How to Create Volatile Table in Teradata?
Last Updated :
11 Aug, 2021
Volatile tables are as same as simple tables but with a small difference i.e. they are volatile in nature.
Like a simple table, the volatile table is also formed by the user and can only be used until the user is logged into. Once the user is logged off or disconnects, the Teradata manager automatically drops the table from the session.
After dropping the table by Teradata manager, the data and definition inserted in the volatile table will be erased automatically.
How can you use the volatile table?
Suppose, you are the user and working with the Teradata database and you have to form a couple of tables in the same database. The first option is you have to create simple tables in the same database and drop them after use.
The second option is you can create volatile tables whose data and definition are automatically dropped by the Teradata database after you logged off from the database and that will be the more smart way.
We will follow the below syntax for volatile table syntax.
Syntax:
CREATE [SET | MULTISET] VOLATILE TABLE TABEL_NAME
(
COLUMN1 DATATYPE;
COLUMN2 DATATYPE;
.
.
.
COLUMN_N datatype)
<INDEX_DEFINITION>
ON COMMIT [DELETE|PRESERVE] ROWS;
Example:
The following example will create a volatile table of the name 'geek'.
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.
Data insertion in the volatile table:
Let's insert some data in the volatile table.
INSERT INTO GEEK VALUES (1,'Aman','Goyal');
INSERT INTO GEEK VALUES (2,'Pritam','Soni');
INSERT INTO GEEK VALUES (3,'Swati','Jain');
Select data from the volatile table:
We will run the select statement into the volatile table.
SELECT * FROM GEEK ORDER BY ROLLNO;
Output:
At last, if we disconnect from the current session and after re-logging, run the same select statement again, we will find that the table student does not exist anymore in the database.
Output after re-logging:
SELECT * FROM GEEK ORDER BY ROLLNO;
*** Failure 3807 Object 'GEEK' does not exist.
Statement# 1, Info =0
*** Total elapsed time was 1 second
Similar Reads
How to Create a View on a TEMP Table in SQL?
In SQL Server, TEMP tables are used to store data temporarily during the session in which they are created. These tables are especially useful for storing intermediate results or simplifying complex queries. In this article, We will learn about whether can we create a view on a TEMP table in SQL Ser
4 min read
How to Connect Teradata Using SAS in SQL?
SAS is a popular statistical software that provides a powerful suite of tools for data management, analytics, and reporting. In this blog post, we will show you how to connect to Teradata using SAS in SQL. Teradata is a high-performance, relational database management system that is widely used for
3 min read
How to create table in Ruby on Rails?
In Ruby on Rails, creating tables involves using migrations, which are a powerful mechanism for managing database schema changes. Here's a detailed breakdown of the process: 1. Database Setup (Optional): While APIs can function without databases, many Rails applications use them for data persistence
3 min read
Create Table in MariaDB
MariaDB is an open-source RDBMS that has become famous for its speed, and scalability. MariaDB Stores data in tables with structured relationships between them. In terms of working with databases, one crucial element involves the construction of tables for organizing and storing data effectively. In
4 min read
How to Create Table in AWS Athena
AWS Athena is a powerful and useful tool that allows users to analyze data stored in Amazon S3 using SQL. One of the most important step to use athena is creating the table to organize the data and query it to get the desired results. In this article we will see how to create the table in aws athena
5 min read
Python SQLite - Create Table
In this article, we will discuss how can we create tables in the SQLite database from the Python program using the sqlite3 module. In SQLite database we use the following syntax to create a table: CREATE TABLE database_name.table_name(                     column1 datatype PRIMARY
2 min read
How to Declare a Variable in SQL?
Variables in SQL are fundamental for building efficient and scalable database applications. They enhance the flexibility and efficiency of database queries by acting as placeholders for data. Understanding how to declare and use variables in SQL is crucial for writing dynamic and effective queriesIn
3 min read
How to Move a Table from SAS to Teradata SQL Assistant?
Organizations looking to optimize their analytical talents need to be capable of moving facts among structures without difficulty inside the facts-centric world these days. Data migration from SAS, a pinnacle analytics platform, to Teradata SQL Assistant, a powerful device for Teradata database cont
4 min read
How to Drop a Temporary Table If It Exists
Temporary tables are an essential feature in database management systems like MySQL and SQL Server. They allow developers to store intermediate data for the duration of a session by providing flexibility and efficiency in handling complex queries. Managing these tables correctly including knowing ho
4 min read
How to Create One Table From Another Table in SQL
Creating a table based on the structure and data of an existing table is a common task in database management. This process allows us to replicate a table for backup, testing or data transformation purposes. SQL provides efficient methods to create one table from another while preserving the schema,
3 min read