0% found this document useful (0 votes)
272 views14 pages

Module 6: Creating A Teradata Database

This document provides information about Teradata databases and users. It defines what a Teradata database and user are, and describes how they are used to define logical spaces for objects and permissions. It also explains key concepts like perm space, spool space, and temporary space that can be allocated for databases and users. The document concludes with examples of creating tables and indexes within a database.

Uploaded by

aadil211
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
272 views14 pages

Module 6: Creating A Teradata Database

This document provides information about Teradata databases and users. It defines what a Teradata database and user are, and describes how they are used to define logical spaces for objects and permissions. It also explains key concepts like perm space, spool space, and temporary space that can be allocated for databases and users. The document concludes with examples of creating tables and indexes within a database.

Uploaded by

aadil211
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Module 6: Creating a Teradata Database

After completing this module, you will be able to:

• Distinguish between a Teradata Database and Teradata User.

• Define Perm Space and explain how it is used.

• Define Spool Space and its use.

• Visualize the hierarchy of objects in a Teradata system.


A Teradata Database
A Teradata database is a defined logical repository for:
• Tables • Join Indexes
• Views • Hash Indexes
• Macros • Permanent Journals
• Triggers • User-defined Functions
• Stored Procedures

Attributes that may be specified for a database:


• Perm Space – maximum amount of space available for tables
• Spool Space – maximum amount of work space available for requests
• Temp Space – maximum amount of temporary table space
A Teradata database is created with the CREATE DATABASE command.

Example CREATE DATABASE Database_2 FROM Sysdba


AS PERMANENT = 20e9, SPOOL = 200e6;

Notes:
"Database_2" is owned by "Sysdba".
A database is empty until objects are created within it.
A Teradata User
A Teradata user is a database with an assigned password.
A Teradata user may logon to Teradata and access objects within:
• itself
• other databases for which it has access rights
Examples of attributes that may be specified for a user:
• Perm Space – maximum amount of space available for tables
• Spool Space – maximum amount of work space available for requests
• Temp Space – maximum amount of temporary table space
A user is an active repository while a database is a passive repository.
A user is created with the CREATE USER command.

Example CREATE USER User_C FROM User_A


AS PERMANENT = 10e6
,SPOOL = 100e6
,TEMPORARY = 80e6
,PASSWORD = lucky_day ;
"User_C" is owned by "User_A".
A user is empty until objects are created within it.
Database – User Comparison
User Database
Unique Name Unique Name
Password = Value
Define and use Perm space Define and use Perm space
Define and use Spool space Define Spool space
Define and use Temporary space Define Temporary space
Set Fallback protection default Set Fallback protection default
Set Permanent Journal defaults Set Permanent Journal defaults
Multiple Account strings One Account string
Logon and establish a session with a priority
May have a startup string
Default database, dateform, timezone,
and default character set
Collation Sequence

• You can only LOGON as a known User to establish a session with Teradata.
• Tables and Stored Procedures require Perm Space.
• Views, Macros, and Triggers are definitions in the DD/D and require no Perm Space.
• A database (or user) with zero Perm Space may have views, macros, and triggers, but
cannot have tables, stored procedures, or user-defined functions.
Hierarchy of Databases and Users
Maximum Perm Space - available
but not yet assigned
User DBC Current Perm Space - contains
tables or stored procedures
No Box No Perm Space
User SYSDBA

User_A User D
Database_1 Database_2 Database_3

User_B User_C

• A new database or user must be created from an existing database or user.?


• All Perm space specifications are subtracted from the immediate owner or parent.
• Perm space is a zero sum game – the total of all Perm Space allocations must equal the
total amount of disk space available to Teradata.
• Perm space is only used for tables and stored procedures.
• Perm space currently unused is available to be used as Spool or Temp space.
Example of a System Hierarchy
DBC

CrashDumps QCD Sys_Calendar SysAdmin SysDBA SystemFE

A User and/or a Customer_Service


Database may be given
PERM space.
CS_Users CS_View_Mac CS_Tables
In this example, Mark
and Tom have no View_1 Table_1
PERM space, but View_2 Table_2
Mark Tom Susan
Table_3
Susan does. Macro_1
Table_4
Macro_2

Users may use views and macros


to access the actual tables.
Permanent Space

CREATE DATABASE CS_Tables FROM Customer_Service


AS PERMANENT = 80e9 BYTES, ...

AMP AMP AMP AMP AMP AMP AMP AMP

Perm Space
Limit per AMP 10 GB 10 GB 10 GB 10 GB 10 GB 10 GB 10 GB 10 GB

• Table rows, index subtable rows, and stored procedures row use Perm space.
• Fallback protection uses twice the Perm space of No Fallback?.
• Perm space is deducted from the owner’s database space.
• Disk space is not reserved ahead of time, but is available on demand.
• Perm space is defined globally for a database.
• Perm space can be dynamically modified.
• The (global limit)? divided by the number of AMPs is the per/AMP limit.
• The per/AMP limit cannot be exceeded.
• Good data distribution is crucial to space management.
Spool Space

CREATE USER Susan FROM CS_Users AS PERMANENT = 40e6 BYTES,


SPOOL = 240e6 BYTES, PASSWORD = secret …

AMP AMP AMP AMP AMP AMP AMP AMP

Spool Space
Limit per AMP 30 MB 30 MB 30 MB 30 MB 30 MB 30 MB 30 MB 30 MB

• Spool space is work space acquired automatically by the system for


intermediate query results or answer sets.
– SELECT statements generally use Spool space.
– Only INSERT, UPDATE, and DELETE statements affect table contents.
• The Spool limit cannot exceed the Spool limit of the original owner.
• The Spool limit is divided by the number of AMPS in the system, giving a per-
AMP limit that cannot be exceeded.
– "Insufficient Spool" errors often result from poorly distributed data or joins on
columns with large numbers of non-unique values.
– Keeping Spool rows small and few in number reduces Spool I/O.?
Temporary Space

CREATE USER Susan FROM CS_Users AS PERMANENT = 40e6 BYTES,


SPOOL = 240e6 BYTES, TEMPORARY = 120e6 BYTES, PASSWORD = secret …

AMP AMP AMP AMP AMP AMP AMP AMP

Temporary
Space Limit
per AMP
15 MB 15 MB 15 MB 15 MB 15 MB 15 MB 15 MB 15 MB

• Temporary space is space acquired automatically by the system when a


"Global Temporary" table is used and materialized.
• The Temporary limit cannot exceed the Temporary limit of the original owner.
• The Temporary limit is divided by the number of AMPS in the system, giving a
per-AMP limit that cannot be exceeded.
– "Insufficient Temporary" errors often result from poorly distributed data or joins on
columns with large numbers of non-unique values.

• Note: Volatile Temporary tables and derived tables utilize Spool space.
Creating Tables
Creating a table requires ...
– defining columns
– assignment of a primary index (either by user or Teradata)
– optional assignment of secondary indexes
CREATE TABLE Employee
(Employee_Number INTEGER NOT NULL
,Last_Name CHAR(20) NOT NULL
,First_Name VARCHAR(20)
,Salary_Amount DECIMAL(10,2)
,Department_Number SMALLINT
,Job_Code CHAR(3))
Primary  UNIQUE PRIMARY INDEX (Employee_Number)
Secondary INDEX (Last_Name) ;

Tables
Database objects may be created or CREATE Views
dropped as needed. Macros
DROP
Triggers
Procedures
Secondary indexes may be
– created at table creation
CREATE
– created after table creation INDEX (secondary only)
– dropped after table creation DROP
Data Types
TYPE Name Bytes Description

Date/Time DATE 4 YYYYMMDD


TIME (WITH ZONE) 6/8 HHMMSSZZ
TIMESTAMP (WITH ZONE) 10 / 12 YYYYMMDDHHMMSSZZ

Numeric DECIMAL (18,18) 2, 4, 8 + OR -


NUMERIC (18,18) 2, 4, 8 + or -
BYTEINT 1 -128 to +127
SMALLINT 2 -32,768 to +32,767
INTEGER 4 -2,147,483,648 to +2,147,483,647
FLOAT 8 IEEE floating pt

Byte BYTE(n) 0 – 64,000


VARBYTE (n) 0 – 64,000
BLOB 0 – 2 GB Binary Large Object (V2R5.1)

Character CHAR (n) 0 – 64,000


VARCHAR (n) 0 – 64,000
LONG VARCHAR same as VARCHAR (64,000)
GRAPHIC 0 – 32,000
VARGRAPHIC 0 – 32,000
LONG VARGRAPHIC same as VARGRAPHIC(32,000)
CLOB 0 – 2 GB Character Large Object
Access Rights and Privileges
Data Definition Privileges A Sample Scenario
Command Object
Database and/or User
CREATE Table and/or View
DROP Macro and/or Trigger P
Stored Procedure R
Role and/or Profile
O
G
Data Manipulation Privileges R
SELECT U
INSERT Table A
D S
UPDATE View M
DELETE B E
M
A R
EXECUTE Macro and/or Stored Procedure E ADMIN
R
Data Control Privileges S
DUMP Database O
RESTORE Table P
CHECKPOINT Journal E
Privileges on
R
GRANT Databases
REVOKE Users
Objects
Review Questions
True or False
____ 1. A database will always have tables.
____ 2. A user will always have a password.
____ 3. A user creating a subordinate user must give up some of his/her Perm Space.
____ 4. Creating tables requires the definition of at least 1 column and the user assignment of a
Primary Index.
____ 5. The sum of all user and database Perm Space will equal the total space on the system.
____ 6. The sum of all user and database Spool Space will equal the total space on the system.
____ 7. Before a user can read a table, a database or table SELECT privilege must exist in the DD/D
for that user.
____ 8. Deleting a macro from a database reclaims Perm Space for the database.

9. Which of the following is FALSE about PERM space? ____


a. PERM space can be dynamically modified.
b. The per/AMP limit of PERM space can not be exceeded.
c. Maximum PERM space can be defined at the database or table level.
d. Tables, index subtables, and stored procedures use PERM space.

10. Which of the following is FALSE about SPOOL space? ____


a. SPOOL space can be dynamically modified.
b. The per/AMP limit of SPOOL space can not be exceeded.
c. Maximum SPOOL space can be defined at the database or user level.
d. Maximum SPOOL space can be defined at a value greater than the immediate parent's
Module 6: Review Question Answers
True or False
False 1. A database will always have tables.
True 2. A user will always have a password.
False 3. A user creating a subordinate user must give up some of his/her Perm Space.
False 4. Creating tables requires the definition of at least 1 column and the user
assignment of a Primary Index.
True 5. The sum of all user and database Perm Space will equal the total space on the
system.
False 6. The sum of all user and database Spool Space will equal the total space on the
system.
True 7. Before a user can read a table, a database or table SELECT privilege must exist
in the DD/D for that user.
False 8. Deleting a macro from a database reclaims Perm Space for the database.

9. Which of the following is FALSE about PERM space? ____


a. PERM space can be dynamically modified.
b. The per/AMP limit of PERM space can not be exceeded.
c. Maximum PERM space can be defined at the database or table level.
d. Tables, index subtables, and stored procedures use PERM space.

10. Which of the following is FALSE about SPOOL space? ____


a. SPOOL space can be dynamically modified.
b. The per/AMP limit of SPOOL space can not be exceeded.

You might also like