The following procedure shows how to create tables using BTEQ, but you can also use Teradata Studio.
- Logon on to Vantage as user DBADMIN using BTEQ.
- Create one or more tables using the CREATE TABLE statement. For example:
CREATE SET TABLE database_name.table_name, (column_name data_type, column_name data_type, column_name data_type) UNIQUE PRIMARY INDEX (primary_index_column);
- MULTISET
- SET
- A MULTISET table allows duplicate rows in compliance with the ANSI/ISO SQL 2011 standard. A SET table does not allow duplicate rows.
- database_name
- The name of the database where the table will be created if it is different from the current database.
- table_name
- The name of the table to be created.
- [NO] FALLBACK
- Specifies that the system will automatically create a duplicate copy of the current image of every row in this table to provide backup in case of a failure.
- column_name
- Specifies the name of one or more columns, in the order in which they and their attributes are to be defined for the table.
- data_type
- Specifies a single data type for each column.
- [UNIQUE|NO] PRIMARY INDEX
- Specifies the primary index. A table can have no more than one primary index. If you do not explicitly assign a primary index, Vantage will choose a default primary index (unless you specify NO PRIMARY INDEX).
- primary_index_column
- Specifies the column(s) that define a primary index. If you specify more than one column, the index is created on the combined values of each column. You can specify up to 64 columns.
The example is the minimum recommended specification for creating a table. You can specify additional options, or add them later using the ALTER TABLE statement, see Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144.To automate the creation of data tables by using BTEQ scripts, see Using BTEQ Scripts to Create Database Objects.
- Set privileges on the table so that only designated administrative users can access the table directly.
- Collect statistics on the newly created, empty table. This defines the columns, indexes, and partitions for a PPI table, as well as the data structures for subsequent collection of statistics and demographics.
Optional Table-level and Column-level Elements
The following are common optional table-level elements you can specify in the CREATE/ALTER TABLE statement. For details about these table options and for a complete description of all table options, see Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144.
Syntax Element | Explanation |
---|---|
GLOBAL TEMPORARY | Creates a global temporary table. Global temporary tables have a persistent definition but do not have persistent contents across sessions. Each user session can materialize up to 2,000 global temporary tables at a time. To use global temporary tables, create or modify the user or profile to have a temporary space limit by using the TEMPORARY = n BYTES option. If no temporary space limit is defined for a profile, Analytics Database uses the temporary space limit defined for the individual user-creator. If no temporary space is defined for a user, then the space allocated for any materialized global temporary tables referenced by that user is set to the maximum temporary space allocated for the immediate owner. |
JOURNAL | Specifies a Permanent Journal (PJ) for the table, which stores an image of each data row that has been changed with an INSERT, UPDATE, or DELETE statement. PJ images can reflect row values as they appeared before the change, after the change, or both. To specify a PJ for all tables in a database, use the JOURNAL clauses in the CREATE DATABASE statement. Recommendation: Specify journaling for tables that need an additional level of data protection after you have analyzed data protection needs. |
FREESPACE | Specifies the percent of free space
that remains on a cylinder during loading operations. Reserved free space allows tables to expand within their currently allocated cylinders. This can prevent or delay the need for additional cylinders to be allocated, which incurs the overhead of moving data to the new cylinders. Avoiding new cylinder allocations can improve overall system performance. You can control this space at the global and
table level. Recommendation: If little or no table expansion is expected (the table is read-only), set FREESPACE to 0. Otherwise, choose a percentage that reflects the growth rate of your table (INSERTs minus DELETEs). Common settings are 5 to 15%. The maximum allowed is 75%. |
DATABLOCKSIZE | Specifies the maximum data block
size for blocks that contain multiple rows. Larger block sizes
enhance full table scan operations by selecting more rows in a
single I/O. Smaller block sizes are best for transaction-oriented
tables to minimize overhead by retrieving only what is needed. You
can control the data block size at the global and table level. Recommendation: Use a larger value if the database is used primarily for strategic work (decision support/complex queries). Use a smaller value if the database is used primarily for tactical work (OLTP). |
[UNIQUE] INDEX | Specifies secondary indexes for the table. Secondary indexes (SI) allow quick access to table data using an alternate, less frequently used path than the primary index. SIs improve performance by avoiding full table scans. |
PARTITION BY | Specifies that the primary index is partitioned based on the value of the specified partitioning expression. A partitioned primary index (PPI) permits rows to be assigned to user-defined data partitions, enabling enhanced performance for range queries while providing efficient PI join strategies. See Row Partitioning. |
The following are common optional column-level elements you can specify in the CREATE/ALTER TABLE statement. For details about these column-level options and for a complete description of all table options, see Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144.
Syntax Element | Explanation |
---|---|
data_type_attributes | If you specify attributes for a
column, you must define its data type before you define its
attributes. The following attributes are supported:
Recommendation: Teradata highly recommends that you specify the NOT NULL attribute for columns that will never be null. |
COMPRESS | Specifies a set of distinct values
in a column that is to be compressed to zero space. Column
compression can enhance storage capacity, improve response time for
table scans, and reduce disk I/O traffic. Recommendation: For best results, use multivalue compression where:
|
CONSTRAINT | Specifies column-level constraints. The following constraints are supported:
Recommendation: Specify a name for the constraint specification. |
Example of the CREATE TABLE Statement
This table definition creates the Employee table in the database named Tables_Database:
CREATE SET TABLE Tables_Database.Employee, (Associate_Id INTEGER, Associate_Name CHAR(25), Salary DECIMAL(8,2), DOB DATE, Job_Title VARCHAR(25), Dept_No SMALLINT, Marital_Status CHAR, No_Of_Dependents BYTEINT) UNIQUE PRIMARY INDEX (Associate_Id);
Using BTEQ script, see Using BTEQ Scripts to Create Database Objects.
Related Information
Topic | Resources for Further Information |
---|---|
An overview of tables, including global temporary and volatile tables | Teradata Vantage™ - SQL Fundamentals, B035-1141 |
Syntax, options, and required
privileges for the following:
|
Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144 |
The default database | Teradata Vantage™ - SQL Fundamentals, B035-1141 |
Data types and data type attributes | Teradata Vantage™ - Data Types and Literals, B035-1143 |
|
Choosing a Primary Index |
Using the FREESPACE option to manage performance, and guidelines for calculating a FREESPACE value | FREESPACE table option in Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144 and “FreeSpacePercent” DBS Control field in Teradata Vantage™ - Database Utilities, B035-1102 |
Using the DATABLOCKSIZE option to manage performance and specifying a DataBlockSize value | DATABLOCKSIZE table option in Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144 and "DataBlockSize" DBS Control field in Teradata Vantage™ - Database Utilities, B035-1102 |
Compressing column values | Teradata Vantage™ - Database Design, B035-1094 |
Column-level and table-level constraints | Teradata Vantage™ - Database Design, B035-1094 |