Updated July 6, 2023
Introduction to Teradata Create Table
The following article provides an outline for Teradata Create Table. Every sequential database involves the storage of its data in the form of tables. Tables are structures of data which are in row and column format. The columns are vertical entities, whereas the rows are horizontal entities. Here the position in which the row and the columns meet is called a field. Here a table can also be mentioned as an organized collection of the same types of data. The number of rows and tables in a table depends on the space allocated to the table; to create a table in a database, the create table statement is used.
The create table statement is responsible for creating a table in the database. Here Teradata systems also uses the create table statement for the creation of the tables. Teradata more specifically allows the flexibility of allocating the table space or the memory needed for each and every table created more specifically.
Syntax of Teradata Create Table
Given below is the syntax mentioned:
CREATE SET/MULTISET TABLE Name_of_database.Name_of_Table, [NO] FALLBACK
(Name_of_Column#1 Column_Name#1_data_type attribute,
Name_of_Column#2 Column_Name#2_data_type attribute,
Name_of_Column#3 Column_Name#3_data_type attribute,
Name_of_Column#4 Column_Name#4_data_type attribute,
Name_of_Column#N Column_Name#N_data_type attribute)
UNIQUE PRIMARY INDEX (Name_of_Primary_Index_column);
- When SET is mentioned in the table creation, it does not permit duplicate rows; in the MULTISET table, duplicate values are allowed. Here the database name and the table name must be mentioned.
- When a FALLBACK is cited, then the device will generate a replica desk, and this replica desk might be useful when there may be a failure to the device.
- The default fee is NO FALLBACK. For every column in the database, their corresponding column datatypes need to be specified; these data types need to be ensured to match the nature of the column.
- Also, the primary index of the table can be created; here, the column which is expected to be used as the primary index needs to be mentioned in the UNIQUE primary index keyword.
Options in Creating Teradata Tables
There are several options in the ways a table can be created in Teradata; these options are given below:
Options | Definition |
Example |
GLOBAL TEMPORARY TABLE | Creating tables with this option allows the contents of the table to be active for only one specific session. When the session ends, the contents of the table will be deleted. | CREATE GLOBAL TEMPORARY TABLE EDUCBA.Global_Table ( ID INT, Employee_Name VARCHAR (50) ); |
JOURNAL TABLE | The permanent journal table will allow maintaining a log of information about the inserts, updates etc., to the table. This is sequential information about the changes to the table. During processes like COMIT or ABORT, these journal tables will be helpful in securing the user data. The JOURNAL option will be default created for a database which means every table in a database will have a Journal activated in the backend by default. If we expect them to set off the JOURNAL option for a specific table, then the query shared will be helpful. | CREATE GLOBAL TEMPORARY TABLE EDUCBA.Global_Table FALLBACK, NO AFTER JOURNAL ( ID INT, ); |
FREESPACE | The free space option allows to confirm the amount of space available on the storage cylinders during the load operation being performed. | NA |
DATABLOCKSIZE | This option allows to confirm the total number of sectors for each block. Each sector is 512 MB in size. | NA |
INDEX | This represents the unique secondary index for the table. Here the secondary index values will be stored to a sub table. Hence more storage will be needed. The secondary indexes can be created with both unique and Non-Unique indexes. The USI sub table rows are hashed, whereas the NUSI is AMP which means each row in the NUSI table will directly match to the corresponding primary table. The secondary index creation process can be applied during the table creation or even after the table is created. The Secondary Index creation option is Optional. | USI:
CREATE UNIQUE INDEX(ID) on EDUCBA.Global_Table; NUSI: CREATE INDEX(ID) on EDUCBA.Global_Table;
|
Examples of Teradata Create Table
Given below are the examples of Teradata Create Table:
Example #1
The first example represents the creation of a SET table, so this table does not allow any duplicate rows. Here 3 columns are created for the table, such as ID, NAME, AGE. Each of these columns is associated with its corresponding data types. The output snaps involve snaps of the table are created, and then the schema of the table is verified. After that, the insert operation is executed on the table. The inserted records are displayed in the snap too.
Code:
CREATE SET TABLE EDUCBA.TEST (ID INTEGER, NAME VARCHAR(50),AGE INTEGER);
INSERT INTO EDUCBA.TEST(ID, NAME, AGE) VALUES (10,'ÁNAND',34)
INSERT INTO EDUCBA.TEST(ID, NAME, AGE) VALUES (13,'MANJU',36)
INSERT INTO EDUCBA.TEST(ID, NAME, AGE) VALUES (14,'SAVITHA',34)
INSERT INTO EDUCBA.TEST(ID, NAME, AGE) VALUES (12,'RAJESH',34)
SELECT * FROM EDUCBA.TEST;
Output:
Example #2
The first example represents the creation of a MULTISET table, so this allows duplicate rows. Here 5 columns are created for the table, such as ID, NAME, AGE. Each of these columns is associated with its corresponding data types. We can notice from the output file that the insertion of duplicate values in all the columns are comfortably inserted in the table. These duplicate values are printed on to the console, and a snap of the console is captured and attached below. Also, all the insert queries are shared below in the query section.
Code:
CREATE MULTISET TABLE EDUCBA.TEST_MULTI(ID INTEGER, NAME VARCHAR(50),AGE INTEGER);
INSERT INTO EDUCBA.TEST_MULTI (ID, NAME, AGE) VALUES (10,'ÁNAND',34)
INSERT INTO EDUCBA.TEST_MULTI (ID, NAME, AGE) VALUES (10,'ÁNAND',34)
INSERT INTO EDUCBA.TEST_MULTI (ID, NAME, AGE) VALUES (10,'ÁNAND',34)
INSERT INTO EDUCBA.TEST_MULTI (ID, NAME, AGE) VALUES (10,'ÁNAND',34)
INSERT INTO EDUCBA.TEST_MULTI (ID, NAME, AGE) VALUES (10,'ÁNAND',34)
SELECT * FROM EDUCBA.MULTI_TEST;
Output:
Conclusion
The create table statement in Teradata systems are very deeply defined such that it is designed to have the capability of formulating tables which can store a solidified amount of data, and also, they have the ability to flexibly mention the memory and index level options for these table items. This is one among the key capabilities that make Teradata among the successful sequential storage-based enterprises around the globe.
Recommended Articles
We hope that this EDUCBA information on “Teradata Create Table” was beneficial to you. You can view EDUCBA’s recommended articles for more information.