Teradata - Create Tables


Advertisements

CREATE TABLE command is used to create tables in Teradata.

Syntax

Following is the generic syntax of CREATE TABLE statement.

CREATE <SET/MULTISET> TABLE <Tablename> 
<Table Options> 
<Column Definitions> 
<Index Definitions>;
  • Table Options − Specifies the physical attributes of the table such as Journal and Fallback.

  • Column Definition − Specifies the list of columns, data types and their attributes.

  • Index Definition − Additional indexing options such as Primary Index, Secondary Index and Partitioned Primary Index.

Example

The following example creates a table called employee with FALLBACK option. The table contains 5 columns with EmployeeNo as the Unique Primary Index.

CREATE SET TABLE EMPLOYEE,FALLBACK ( 
   EmployeeNo INTEGER, 
   FirstName VARCHAR(30), 
   LastName VARCHAR(30), 
   DOB DATE FORMAT 'YYYY-MM-DD', 
   JoinedDate DATE FORMAT 'YYYY-MM-DD', 
   DepartmentNo BYTEINT 
) 
UNIQUE PRIMARY INDEX ( EmployeeNo );

Once the table is created, you can use SHOW TABLE command to view the Definition of the table.

SHOW TABLE Employee; 
*** Text of DDL statement returned. 
*** Total elapsed time was 1 second. 
------------------------------------------------------------------------  
CREATE SET TABLE EMPLOYEE ,FALLBACK , 
   NO BEFORE JOURNAL, 
   NO AFTER JOURNAL, 
   CHECKSUM = DEFAULT, 
   
   DEFAULT MERGEBLOCKRATIO (
      EmployeeNo INTEGER, 
      FirstName VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC, 
      LastName VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC, 
      DOB DATE FORMAT 'YYYY-MM-DD', 
      JoinedDate DATE FORMAT 'YYYY-MM-DD', 
      DepartmentNo BYTEINT
   ) 
UNIQUE PRIMARY INDEX ( EmployeeNo );
teradata_tables.htm
Advertisements