Sunteți pe pagina 1din 15

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
Views
Macros
Triggers
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;

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
Password = Value
Define and use Perm space
Define and use Spool space
Define and use Temporary space
Set Fallback protection default
Set Permanent Journal defaults
Multiple Account strings
Logon and establish a session with a priority
May have a startup string
Default database, dateform, timezone,
and default character set
Collation Sequence

Unique Name

Define and use Perm space


Define Spool space
Define Temporary space
Set Fallback protection default
Set Permanent Journal defaults
One Account string

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 or stored procedures.

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
Database_1

Database_2

User D

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

SysAdmin

SysDBA

SystemFE

Customer_Service

A User and/or a
Database may be given
PERM space.
In this example, Mark
and Tom have no
PERM space, but
Susan does.

Sys_Calendar

CS_Users

Mark

Tom

Susan

CS_View_Mac

CS_Tables

View_1
View_2

Table_1
Table_2
Table_3
Table_4

Macro_1
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

Perm Space
Limit per AMP

AMP

AMP

AMP

AMP

AMP

AMP

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 owners 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
Spool Space
Limit per AMP

AMP

AMP

AMP

AMP

AMP

AMP

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 perAMP 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
Temporary
Space Limit
per AMP

AMP

AMP

AMP

AMP

AMP

AMP

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.

System Variables and Keywords


As the requesting user, system variables and the help function can be used to
display information about your session, objects within a database/user, etc.
USER
DATABASE

username
current database

ACCOUNT account id
SESSION session #

Example 1:
SELECT

USER, ACCOUNT,
SESSION, DATABASE;

User
SUSAN

Account
$M_9038

Session
1000

Database
SUSAN

DATABASE Order_DB;
SELECT USER, ACCOUNT,
SESSION, DATABASE;

User
SUSAN

Account
$M_9038

Session
1000

Database
Order_DB

Table/View/Macro Name
customer
cust_orders

TableKind
T
V

Comment
?
?

cust_ord_ix
orders
orders_hash_1
orders_ix_cust_id
set_ansidate_on

I
T
N
I
M

?
?
?
?
?

Example 2:
HELP USER Order_DB;

Creating Tables
Creating a table requires ...
defining columns
assigning of a primary index
optional assignment of secondary indexes
CREATE TABLE Employee
(Employee_Number
,Last_Name
,First_Name
,Salary_Amount
,Department_Number
,Job_Code
Primary
Secondary

INTEGER NOT NULL


CHAR(20) NOT NULL
VARCHAR(20)
DECIMAL(10,2)
SMALLINT
CHAR(3))

UNIQUE PRIMARY INDEX (Employee_Number)


INDEX (Last_Name) ;

Database objects may be created or


dropped as needed.
Secondary indexes may be
created at table creation
created after table creation
dropped after table creation

CREATE
DROP

CREATE
DROP

Tables
Views
Macros
Triggers
Procedures

INDEX (secondary only)

Data Types
TYPE

Name

Date/Time DATE
TIME (WITH ZONE)

Numeric

Byte

Character

Bytes

Description

YYYYMMDD

6/8

HHMMSSZZ

TIMESTAMP (WITH ZONE)

10 / 12

YYYYMMDDHHMMSSZZ

DECIMAL (18,18)

2, 4, 8

+ OR -

NUMERIC (18,18)

2, 4, 8

+ or -

BYTEINT

-128 to +127

SMALLINT

-32,768 to +32,767

INTEGER

-2,147,483,648 to +2,147,483,647

FLOAT

IEEE floating pt

BYTE(n)

0 - 64,000

VARBYTE (n)

0 - 64,000

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)

Access Rights and Privileges


Data Definition Privileges
Command
CREATE
DROP

A Sample Scenario

Object
Database and/or User
Table and/or View
Macro and/or Trigger
Stored Procedure
Role and/or Profile

Data Manipulation Privileges


SELECT
INSERT
UPDATE
DELETE

Table
View

EXECUTE

Macro and/or Stored Procedure

Data Control Privileges


DUMP
RESTORE
CHECKPOINT

Database
Table
Journal

GRANT
REVOKE

Privileges on
Databases
Users
Objects

D
B
A

P
R
O
G
R
A
M
M
E
R
S

U
S
E
R

ADMIN
O
P
E
R

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 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.
b.
c.
d.

PERM space can be dynamically modified.


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

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


a.
b.
c.
d.

SPOOL space can be dynamically modified.


The per/AMP limit of SPOOL space can not be exceeded.
Maximum SPOOL space can be defined at the database or user level.
Maximum SPOOL space can be defined at a value greater than the immediate parent's value.

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.
system.

The sum of all user and database Perm Space will equal the total space on the

False

6.
system.

The sum of all user and database Spool Space will equal the total space on the

True

7.
that user.

Before a user can read a table, a table SELECT privilege must exist in the DD/D for

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.
b.
c.
d.

PERM space can be dynamically modified.


The per/AMP limit of PERM space can not be exceeded.
Maximum PERM space can be defined at the database or table level.
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.

S-ar putea să vă placă și