A data mart (DM) is the access layer of the Dataware
House(DW) environment that is used to get data out to the
users. The DM is a subset of the DW, usually oriented to a
specific business line or team.
Independent data marts are isolated entities, entirely
separate from the Enterprise Dataware House.
An independent data mart has neither a relationship with the
enterprise data warehouse nor with any other data mart.
These independent data marts are sometimes referred to as data
basements.
Teradata strongly discourages their use.
Dependent Data Marts
Dependent data marts are derived from the enterprise data
warehouse.
Dependent data marts can be built in one of two ways:
Where a user can access both the data mart and
complete data warehouse, depending on need, (or)
the
Where access is limited exclusively to the data mart.
The latter approach is deprecated and the type of data mart it
produces is sometimes referred to as a data junkyard
Logical Data Marts
The logical mart is a form of dependent data mart that is
constructed virtually from the physical data warehouse.
Data is presented to users of the mart using a series of
SQL views that make it appear that a physical data mart
underlies the data available for analysis.
Advantages of Logical Data Marts
Facilitates to design multiple user or department specific
virtual data marts, that provide the same sort of highly
tailored information a physical data mart would without the
need for massive data loads, cleansing, and other necessary
transformations.
Teradata Customer Management provides more relevant conversations
with your customers, which lead to more profitable, satisfying and
longer-lasting relationships by harnessing a powerful combination of
advanced analytics and marketing communication features.
TeraData
• TeraData Database is an ideal foundation for many applications
like,
• Enterprise Data warehousing
• Active Data warehousing
• CRM
• E-Businesses
• Data Marts
Teradata - Single Data Store
Teradata Database acts as
a single data store, with
multiple and different type
of clients can access the
data base concurrently.
Teradata stores the data
once and use it for all
applications.
Teradata supports the entry
level system as it does for
massive enterprise data
warehouse.
Teradata – Unconditional
Parallelism
Teradata Database more faster
than a non-parallel system.
Multi processor work together to
process a task quickly.
The Teradata Database's
parallelism does not depend on
limited data quantity, column
range constraints, or specialized
data models -- The Teradata
Database has "unconditional
parallelism."
Teradata – Ability to model the
Business
Teradata Database's logical architecture, companies can get
a cohesive view of their operations across various functional
areas like
Supply chain - from initial manufacturing, to inventory, to
sale, to delivery, to maintenance, to customer satisfaction.
Relationship - between results of different departments.
Service – Various levels of service based on a customer's
profitability.
A Teradata Database allows the data to represent a business
model, with data organized according to what it represents,
not how it is accessed, so it is easy to understand. The data
model should be designed without regard to usage and be
the same regardless of data volume
Teradata - Mature, Parallel-Aware
Optimizer
The Teradata Database Optimizer is the most robust in the
industry, able to handle:
Multiple complex queries
Multiple joins per query
Unlimited ad-hoc processing
The Optimizer is parallel-aware, meaning that it has
knowledge of system components (how many nodes, vprocs,
etc.). It determines the least expensive plan (time-wise) to
process queries fast and in parallel. The Optimizer is further
explained in the next module.
Teradata - Architecture
Figure shows the typical
architecture of the Teradata
database.
Main Components of
Teradata Database are,
1] Parsing Engine (PE)
2] Banyan Network (BYNET)
3] Access Module Process
(AMP)
4] Disk (Storage)
Teradata – Architecture – Parsing
Engine
Parsing Engine (PE) is the virtual processor that communicates
with the client on one side and with the AMPs (Via BYNET) on
the other side.
PE logically consists of four
components
1] Session Control
2] Parser
3] Optimizer
4] Dispatcher
Session Control - Provides user session management such
as establishing and terminating sessions
Teradata – Architecture – Parsing
Engine
Parser - Interprets the SQL statement received from the
application.
Verifies SQL requests for the proper syntax and evaluates
them semantically.
Consults the Data Dictionary to ensure that all objects exist
and that the user has authority to access them.
Optimizer - develops the least expensive plan, fastest
among the alternatives is chosen. Having knowledge of the
system components.
Dispatcher - controls the sequence in which the steps are
executed and passes the steps received from the optimizer
onto the BYNET for execution by the AMPs
Teradata – Architecture – BYNET
Banyan Network (BYNET) BYNET is a bus that loosely couples all the Symmetric Multi
Processing (SMP) nodes into a multi node system.
BYNET possess high speed logic arrays that provide
bidirectional broadcast.
Normally two BYNET will be provided for Multi node system.
When BYNET traffic becomes particularly heavy, the two
BYNETs can handle separate (rather than redundant) traffic
using Loading – balancing software to optimize the process.
Teradata – Architecture – AMP
Access Module Process(AMP) is the heart of the Teradata
RDBMS. AMP is a virtual processor that provides a BYNET
interface and performs many database and file management
tasks.
AMPs do work associated with generating an output including
sorting, aggregating, formatting and converting.
Each AMP being assigned to a virtual disk and consists of a DB
manager subsystem.
DB manager subsystem manages the query operations like
• Lock databases and tables.
• Create, modify, or delete definitions of tables.
• Insert, delete, or modify rows within the tables.
• Retrieve information from definitions and tables.
• Return responses to the Dispatcher.
Teradata – Architecture - Disk
Disk Arrays –
A disk array is a matrix of independent but interconnected
physical disk storage units.
For the Teradata RDBMS, the disks are organized as a Redundant
Array of Independent Disks (RAID).
RAID consists of 5 types, among these five types one technology
will be chosen by RAID manager.
Each array typically consists of from one to four ranks of disks,
with up to five disks per rank.
Teradata – Architecture - Node
Processor Node –
A hardware assembly containing several, tightly coupled
central processing units (CPUs).
Note : An MPP is a configuration of two or more loosely coupled
SMP nodes with shared SCSI access to multiple disk arrays.
Comprises an SMP configuration with a single processor node
connected to one or more disk arrays with the following
installed on the node:
Database software, Client interface software, Operating
system, Multiprocessor shared memory, processors and
Failsafe power provisions
Teradata
Cliques –
The clique is a feature of multinode systems that physically
groups nodes together by multi ported access to common disk
array units.
Figure illustrates the four node Clique
A journal is a record of some kind of activity.
The Teradata Database supports several kinds of journaling:
Down AMP recovery
Transient Journel
Permanent Journel
Is active during an AMP failure only
Journals fallback tables only
Is used to recover the AMP after the AMP is
repaired, then is discarded
This occurs always.
Transient Journel:
Logs BEFORE images for transactions
Is used by system to roll back failed transactions aborted
either by the user or by the system Captures:
Begin/End Transaction indicators
"Before" row images for UPDATE and DELETE statements
Row IDs for INSERT statements
Control records for CREATE, DROP, DELETE, and ALTER
statements
Keeps each image on the same AMP as the row it describes
Discards images when the transaction or rollback Completes
Occurs always
Permanent Journel:
Is available for tables or databases
Can contain "before" images, which permit rollback,
or after images, which permit roll-forward, or both
before and after images
Provides roll-forward recovery
Provides rollback recovery
Provides full recovery of non-fallback tables
Reduces need for frequent, full-table archives
Occurs as specified by the user.
RAID-1:
RAID-1 is the most common level.
Also called MIRRORING.
With RAID-1, each primary disk has a mirror image,
an exact copy of all its data on another disk. The
contents of both disks are identical.
RAID-5:
RAID 5 protection protects data from being lost because of
a disk unit failure or because of damage to a disk.
RAID
5 protection protects against a one disk unit failure.
RAID5 protects data from single-disk failures with a 25
percent increase in disk storage to provide parity.
Disadvantages of RAID:
RAID1 provides better performance and data protection
than RAID5, but is more expensive.
Even though RAID disk array technology may provide
access
to data even when you have not specified
fallback,
neither RAID-1 nor RAID-5 provides the same level of
protection as fallback does.
Backups need to be done with arcmain for best dataprotection.
The ability of the Teradata RDBMS to maintain an extra copy
of every row of a table in different AMPs.
During normal processing, reads are performed using only
the primary copy, while updates are performed on both
copies.
If a failure renders the primary copy inaccessible, the fallback
copy is used for reads and updates.
The database maintains a log of changes missed by
inaccessible copies and automatically applies the missed
changes to synchronize the table copy when it becomes
accessible.
36
36
Costs and Benefits of Fallback:
The costs of using Fallback include requiring twice the disk
space for storage, and twice the I/O for inserts, updates, and
deletes (all fallback I/Os are performed in parallel to the primary
I/O).
The benefits of Fallback are protecting your data from hardware
failure (VPROC or DSU), protecting your data from software
failure, and automatic recovery after repair is complete,
minimum recovery time after repairs are complete, and
requires no extra I/O for the
SELECT SQL function.
Channel Attached Client
• Channel attached system is accessing the Teradata
through mainframe
• Special hardware is required to access the system,
that why it is called channel attached system,
• Traffic and communications between client
applications on the mainframe and the Teradata
database are managed by the Teradata Director
Program (TDP) software.
MPP – Massive Parallel Processing
Stands for Massive parallel processing.
A computing that uses many CPUs in parallel to execute
a single program.
CPU has its own memory which prevents hold up.
Does not suffer from bottleneck when all CPUs attempt
to access memory once.
Difficult to program as applications must be divided to
communicate with each other.
MPP can support N number of nodes or processors [high
performance].
BTEQ – Basic Teradata Query
– Is a front-end utility for submitting
SQL.
– Operates under all host systems
and local area networks (LANs).
– In batch mode, it obtains input from
a host file (a "BTEQ script").
– Can be used in interactive mode*
– Has import/export features*
– Has report writing features*
Logon, logoff and exit
Logon
Starts a BTEQ Session. Every user, application, or utility must
LOGON to Teradata tosession. establish a
Syntax :
BTEQ .logon LOCALTD/<Database Name>,<Password>
Example :
BTEQ .logon LOCALTD/DBC,DBC
Log off
The LOGOFF command ends the current RDBMS sessions without exiting BTEQ. If
you execute a LOGOFF command while a transaction is in progress, BTEQ aborts
the transaction and backs out any changes that had been made to the database.
Syntax :
.logoff
Exit
Immediately end the current session or sessions and exit BTEQ.
To run a batch file
Run Command Used to Execute Teradata SQL requests and BTEQ
commands from a specified run file, Prepare scripts or macros in txt file
and save Some ware in Hard Disk
Syntax :
.run file = <file path>
Changing Database
In Teradata user itself is database. As a user you will have access to your
own user database and its objects.
The user name you used to logon with is usually your default database.
For Example if you log on as:
.logon user01
Pswd abc, in BTEQ command
The user01 will be your Default Database.
Teradata SQL Assistant
Teradata SQL Assistant
Data Source
Main Window
Windows
Teradata SQL Assistant
Teradata SQL Assistant is an information discovery tool designed for
Windows XP and Windows 2000. Teradata SQL Assistant retrieves data
from any ODBC-compliant database server and allows you to manipulate
and store the data on your desktop PC.
Teradata SQL Assistant
Key features of Teradata SQL Assistant
Teradata SQL Assistant Test Database
Teradata SQL Assistant
Teradata SQL Assistant enables you to combine the data retrieved from ODBC
databases with desktop applications such as Excel to create consolidated reports, or to
analyze the merged data.
Teradata SQL Assistant records all SQL activity, complete with source identification, timings, row counts and your notes. This is especially useful for data mining because you can use the historical record to build
scripts from the SQL that produced positive results.
Key features of Teradata SQL Assistant
• Create reports from any RDBMS that provides an ODBC interface
• Export data from the database to a file on a PC
• Import data from a PC file directly to the database
• Use an import file to create many similar reports (query results or Answer sets).
• Send queries to any ODBC database or the same query to many different databases
• Create a historical record of the submitted SQL with timings and status information such
as success or failure
• Use SQL syntax examples that enable you to tailor statements to best fit your needs
• Use the Database Explorer Tree to easily view database objects
• Use a procedure builder that gives you a list of valid statements for building the logic of a
stored procedure
• Limit data returned to prevent runaway queries
Teradata SQL Assistant Test Database
During the installation process, the options screen gives you a choice to
install a test database (Microsoft Access) on your PC. To use this test
database, you must:
Have approximately 200KB of additional disk space
Install the ODBC desktop driver for Microsoft Access
Use the ODBC Administrator program to define a data
source
Data Source
ODBC Driver
Starting Teradata SQL Assistant
Connecting to and Disconnecting from a Data Source
Changing the Database Password
ODBC Driver
Before using Teradata SQL Assistant to access the data in your RDBMS, you
must first install an ODBC driver.
Each RDBMS requires a driver that is designed specifically for that database
system.
Starting Teradata SQL Assistant
After you have install, start Teradata SQL Assistant before you define an ODBC
data source.
Connecting to a Data Source
Select Tools > Connect. Select a data source and click OK
In the Teradata Database Connect dialog box:
Do one of the following:
•
Select Use Integrated Security
•
Enter the Mechanism and Parameter
•
Enter your Userid and Password.
Optionally, enter a Default Database or an Account String.
Click OK.
56
56
Disconnecting from a Data Source
Select Tools > Disconnect
The status bar, appearing across the bottom of the main window, confirms the
disconnect:
Disconnect successful.
Changing the Database Password
Select Tools > Change Password.
In the Change Database Password dialog box, enter your current password.
Enter your new password (each character you type is displayed as an asterisk).
Re-enter the same new password to confirm it.
Click OK.
Windows
Query Window
The Query window is where you enter and execute a query. The results from your
query are placed into one or more Answerset windows. Alternatively, the results
may be written directly to a file.
To display the Query Window Shortcut Menu
Do one of the following:
From the Query window, click the right mouse button.
Press Shift-F10.
Press Context Menu on your keyboard.
Answerset window
The Answerset window is a table that displays the results from a statement. You can
sort the output in a number of ways and print as bitmaps in spreadsheet format.
Individual cells, rows, columns, or blocks of columns may be formatted to change the
background and foreground color as well as the font style, name, and size. You can
make other modifications such as displaying or hiding gridlines and column headers.
To display the Answerset Window Shortcut Menu
Do one of the following:
• From any table inside the Answerset window, click the right mouse button.
Press Shift+F10
History window
The History window is a table that displays your past queries and related processing
attributes. The past queries and processing attributes are stored locally in a Microsoft
Access 95 or 2000 database. This allows the flexibility to work with previous SQL
statements in the future.
To display the History Window Shortcut Menu
Do one of the following:
Click the right mouse button anywhere within the History window,
Press Shift-F10 or the Context Menu Key
Teradata – CLI
Teradata Call-Level Interface is a collection of callable service
routines that provide the interface between applications and
the Teradata Gateway. Gateway is the interface between CLI
and the Teradata Database
Teradata – Fast Load
Teradata Fastload is a command-driven utility you can use to
quickly load large amounts of data in an empty table on a
Teradata Database.
Data is loaded from
• Disk or tape files on a channel-attached client system
• Input files on a network-attached workstation
• Special input module (INMOD) routines you write to select,
validate, and
Preprocessinput data
• Any other device providing properly formatted source data
• Can be run either through batch mode or Interactive mode
Teradata – Fast Load
What it Does ?
• Log you on to the Teradata Database for a specified
number of sessions, using your username, password, and
tdpid/acctid information
• Load the input data into the Teradata Fastload table on the
Teradata Database.
• Log you off from the Teradata Database.
• If the load operation was successful, return the following
information about the Teradata Fastload operation and then
terminate:
• Total number of records read, skipped, and sent to the
Teradata Database
• Number of errors posted to the Teradata Fastload
error tables
• Number of inserts applied
• Number of duplicate rows
64
Teradata – Fast Load
Limitations
Since FastLoad utility works only on empty tables. You can not use
the FastLoad on the below secnarios
·
·
·
·
65
Insert additional data rows into an existing table
Update individual rows of existing tables
Delete individual rows from existing tables
Load data into multiple tables
Teradata – Multi Load
MultiLoad is a command-driven utility for fast, high-volume maintenance
on multiple tables and views of a Teradata Database
A single MultiLoad job performs a number of different import and delete
tasks on database
tables and views
• Each MultiLoad import task can do multiple data insert, update,
and delete functions on up to five different tables or views.
• Each MultiLoad delete task can remove large numbers of rows
from a single table.
• Supports up to 5 tables
Limitations
MultiLoad doesn’t support the following conditions.
• Concatenation of data files
• Aggregate operators,exponential operators,arithmetic
functions
• Data retrieval from the Teradata Database with the
SELECT
statements
• Foreign key references
• Unique secondary indexes
• Maximum number of columns is limited to 2048
68
Teradata – Tpump
Tpump “Continuous Data Loading”
Teradata TPump is a highly parallel utility designed to
continuously move data from data sources into Teradata tables
without locking the affected table
TPump provides near-real-time data into your data warehouse,
allowing you to maintain fresh,accurate data for up-to-themoment decision making
Tpump is used to insert, update, upsert, and delete data
in the Teradata Database, particularly forenvironments where
batch windows are shrinking and warehouse maintenance
overlaps normal working hours
Teradata Database – Fast Export
FastExport is a command-driven utility that uses multiple
sessions to quickly transfer large amounts of data from tables
and views of the Teradata Database to a client-based application
When FastExport is invoked, the utility executes the FastExport
commands and Teradata SQLstatements in the FastExport job
script. These direct FastExport to
. Log on to the Teradata Database for a specified number of
sessions, using username,
password, and tdpid/acctid information
. Retrieve the specified data from the Teradata Database, in
accordance with format and
selection specifications
.Export the data to the specified file or OUTMOD routine on a
client system
.Log off the Teradata Database
70
Teradata – Teradata Parallel
Transporter (TPT)
Teradata Parallel Transporter(TPT) is a load / update /
export tool that enables data extraction, transformation,
and loading processes common to all data ware houses.
TPT combines the functionality of the Teradata utilities
(Fast Load, Multi Load, Fast Export and Tpump) in a single
parallel environment.
There is a set of open APIs (Application Programmer
Interface) to add third party or custom data transformation
to Teradata Parallel Transporter scripts.
Using multiple, parallel tasks, a single TPT script can load
data from disparate sources into the Teradata DB in the
same job.
Teradata – Teradata Manager
Teradata Corporation offers Teradata Manager as the
command center for monitoring the Teradata Database and
visualizing real-time performance and historical trends
Teradata Manager, which operates from a single graphical
user interface, collects, analyzes, and displays workload
performance and database utilization information in either
report or graphic
format without impacting database users
Some Key features of Teradata Manager
• Performance Analysis andProblem Resolution
• Workload Management
• Database Management
• Operational Control
Access Considerations
For example:
If rows are generally accessed by a range query, consider defining a PPI on
the table that creates a useful set of partitions.
If the table is frequently joined with a specific set of tables, consider
defining the primary index on the column set that is typically used as the
join condition.
Primary index operations must provide the full primary index value.
Primary index retrievals on a single value are always one-AMP operations
Primary indexes
•All Teradata Database tables require a primary index because the system
distributes tables on their primary indexes.
•It helps for the uniform data distribution
•Primary indexes can be:
Unique or Non-unique
Partitioned or Non-partitioned
Unique index
Unique index
A unique index, has a unique value for each row in a table.
Teradata Database defines two different types of unique index.
• Unique primary index (UPI)
UPIs provide optimal data distribution and are typically assigned to the
primary key for a table.
• Unique secondary index (USI)
USIs guarantee that each complete index value is unique, while ensuring
that data access based on it is always a two-AMP operation
Partitioned Primary index
Partitioned primary index (PPI)
It allows rows to be partitioned, based on some set of columns, on the AMP
to which they are distributed, and ordered by the hash of the primary index
columns within the partition
APPI can improve query performance through partition elimination.
A PPI provides a useful alternative to an NPPI for executing range queries
against a table, while still providing efficient access, join, and aggregation
strategies on the primary index
Join Indexes
Join Indexes
A join index is an indexing structure containing columns from one or more
base tables and is generally used to resolve queries and eliminate the need to
access and join the base tables it represents.
Teradata offers a new SQL clause "qualify“.
Oracle doesn't have the Qualify clause altogether. However, Oracle's ability to
do nested query comes to rescue
•
Select from a Dummy table
Sometimes when you are working with SQL you may need an extra row or
two. Oracle has its infamous DUAL table that could be used for that:
Teradata exhibits similar behavior without table name
Table Creation
When creating tables. we have format and default clauses specified in this
table definition. DEFAULT is a standard clause and does what you would
expect. The FORMAT only works when one uses Teradata BTEQ tool as
opposed to a Teradata SQL Assistant.
Use of column aliases
Teradata allows use of column aliases in WHERE conditions
Whereas in Oracle doesn’t permit the use of aliases in where condition
Additional Features
Additional Features:
SHOW Command :
Gives definition(DDL) of the database object.
HELP Command :
Gives the contents of the database object.
MACRO :
Package of pre-written, frequently run SQL statements.
Helpful for reusable queries
It is a package used to execute SQL statements.
Encapsulation of Mulitple SQL statements .
Pre-written SQL statements are there in it.
Actual text of Macros is stored in a Global Repository called
Data Dictionary.
Macros are Database objects and thus they belong to
specific users or database.
Frequently Run SQL statements
Example
Create Macro emp_check(dept integer, sal_amount
dec(9,2) AS (select emp_number from employee where
depart_number=:dept and sal_amount <:sal_amount);
Exec emp_check(201,5000);
Teradata HELP command
Teradata provides one of the user friendly featured like HELP commands.
HELP SESSION:
This command is used to display the user name, account name, logon
date and time, current database name, collation code set and character set
being used and also , transaction semantics, time zone and character set
data.
HELP DATABASE <database-name> ;
This command is used to display the names of all the tables (T), views (V),
macros (M), and triggers (G) stored in a database and table comments
HELP TABLE <table-name>;
This command is used to display the column names, type
identifier, and any user written comments on the columns within
a table.
HELP VIEW <view-name> ;
This command is used to display the column names, type identifier,
and comments on the columns within a VIEW
HELP MACRO <macro-name> ;
This command is used to display the characteristics of parameters
passed to it at execution time.
HELP INDEX <table-name> ;
This command is used to display the indexes and their
characteristics like unique or non-unique and the column or columns
involved in the index. This information is used by the Optimizer to create
a plan for SQL.
This command is used to display values associated with the data demographics collected on the
table. This information is used by the Optimizer to create a plan for SQL.
HELP CONSTRAINT
<table-name>.<constraint-name> ;
This command is used to display the checks to be made on the data when it is inserted or updated
and the columns are involved.
HELP 'SQL';
This command is used to display a list of all available SQL commands and functions.
HELP 'SQL <command>';
This command is used to display the basic syntax and options for the SQL command used in place of
the <command>.
Teradata SHOW command
SHOW CONTROLS:
Purpose
Returns the current settings of the formatting command options.
Displays all of the BTEQ control command options currently configured.
Uses
Use the SHOW CONTROLS command to verify the BTEQ format settings
that users control.
The command SHOW, used without any options, displays the last SQL
statement.
You can use the SHOW CONTROLS command in a Teradata SQL macro.
Optionally, the SHOW CONTROLS command can be used at the settings
level.
SHOW CONTROLS command displays the output at the settings level.
SHOW ERRORMAP
Purpose
Displays the contents of the tables that map error codes to severity levels.
Uses
We can use SHOW ERRORMAP command when you want to display the return code associated
with a specific error.
SHOW VERSIONS
Purpose
Returns the current level of each BTEQ software
Uses
We can use the SHOW VERSIONS command to determine which version of
BTEQ is running.
We can use the SHOW VERSIONS command in a Teradata SQL macro.
.
101
101
Fastload Commands - Sleep
Purpose
• The SLEEP command specifies the number of minutes that
Teradata Fastload pauses before retrying a logon operation
when the maximum number of load operations is already
running on the Teradata Database.
• Syntax: SLEEP minutes
Syntax Element Description:
• minutes Number of minutes that Teradata Fastload pauses
before retrying the logon operation.
• The minutes specification must be greater than zero. If you
enter zero, Teradata Fastload responds with an error
message, and terminates.
• The Teradata Fastload default, if you do not use the SLEEP
command, is 6 minutes.
Tenacity:
Purpose
The TENACITY command specifies the number of hours that
Teradata Fastload continues trying to log on when the
maximum number of load operations is already running on
the Teradata Database.
Syntax:
TENACITY hours
• Syntax Element hours: Number of hours that Teradata
Fastload continues trying to log on.
• The hours specification must be greater than zero. If you
enter zero, Teradata
• Fastload responds with an error message and terminates.
Optimizer & Collecting Statistics
Optimizers are used for choosing the Optimal Executional Plan which
consumes less resources.
Optimizer is helpful in case of:
Multiple complex queries.
Multiple joins per query.
Unlimited ad-hoc processing.
Two types of Optimizers:
Role Based Optimizer (RBO)
Cost Based Optimizer (CBO)
Collecting Statistics
This facilitates the periodic updation of Data Dictionary with
the recent information's about the Database Objects.
The Syntax is:
• COLLECT STATISTICS/
• COLLECT STATS/
• COLLECT STAT
It gives which indexes if any will be used in the query.
Whether individual steps with in the query may execute in parallel.
An estimate of numbers , row which will be processed.
An estimate of the cost of the query.
It does not execute query but explains what DB resources will be used in
processing a request.
EXPLAIN SELECT emplyee_id, emplyee_name,
employee_department from EMPLOYEE;
Invoking Fast load and Multi load
in Batch mode
Fast and Multi load commands can be run using the batch mode by
just passing both the input file and output file as the parameters to
the load utility
Syntax for invoking fast and multi commands are as follows.
Fastload/multiload <Options> < Infile > Outfile
Infile is a Multi/fast Load job script file which includes all MultiLoad
commands and SQL statements.
The outfile is the output stream file.
The below mentioned options can be used while invoking the load
utilites
-b /* only print the brief info which can beused to determine success or failure. */
-c characterset_name /* the name can be ASCII ( 255 )
-e filename /* specifies a file for error messages */
-r ‘MultiLoad Command’ /* the MultiLoad Command may be RUN FILE, so you can run a
job
script */
-M /* maximal number of sessions */
-N /* minimal number of sessions */
108
Rank Function
This example ranks salespersons by sales region based on their
sales.
SELECT sales_person, sales_region, sales_amount,RANK() OVER
(PARTITION BY sales_region ORDER BY sales_amount DESC)
FROM sales_table;
Total, Sub total’s
Teradata WITH and WITH BY clauses can be used to calculate totals and
subtotals.
The below example is used determine the sub total of the salary by
department wise and also the grand total of the salary.
SELECT first_name,last_name,dept_no,salary FROM employee
WITH SUM(salary) (TITLE ‘Department SubTotal:’)BY dept_no -–To calculate subtotal by dept
wise
WITH SUM (salary) (TITLE ‘Total Salary:’); -- To calculate grand total of the salary
first_name last_name dept_no
--------- --------- -------- --------Micheal
Reed
111
Department SubTotal:
Larry
King
112
Philip
Josheph
112
Department SubTotal:
John
Row
113
Department SubTotal:
Read
Vitamin
114
Robert
Howard
114
Department SubTotal:
Tony
Peter
115
Department SubTotal:
Total Salary:
111
Sample Function
Sample function is used to randomly display the records from the table.
Sql Syntax:
select * from tablename sample n
n – represents the number of records to be displayed or also could be
percentage of the records to be displayed
Example
Select * from emp sample 2 – This will display 2 records
A data type conversion modifies the data type or attributes of an expression
and can be either
implicit or explicit.
Explicit conversions can be made using the CAST function or Teradata
conversion syntax.
Forms of Data Type Conversions
The Teradata Database supports the following forms of data conversion:
Implicit
Explicit using the CAST function
Explicit using Teradata conversion syntax
Implicit Type Conversions
Teradata Database permits the assignment and comparison of some types without requiring the
types to be explicitly converted.
Teradata Database also performs implicit type conversions on some argument types passed to
macros, stored procedures, and SQL functions such as SQRT.
Consider the following tables:
CREATE TABLE T1(Fname VARCHAR(25)
,Fid INTEGER,Yrs CHARACTER(2));
CREATE TABLE T2(Wname VARCHAR(25)
,Wid INTEGER,Age SMALLINT);
In the following statement, Teradata Database implicitly converts
the character string in T1.Yrs to a numeric value
UPDATE T2 SET Age = T1.Yrs + 5;
This is not evident in the syntax of the source statement, but
becomes evident when the dictionary information for tables T1
and T2 is accessed.
Implicit Type Conversion During Comparison
Consider the table T1 in Implicit Type Conversion During
Assignment.
In the following statement, Teradata Database implicitly converts both
operands of the comparison operation to FLOAT values before performing the
comparison:
SELECT Fname, Fid FROM T1
WHERE T1.Yrs < 55;
Implicit Type Conversion in Parameter Passing Operations
Consider the SQRT system function that computes the square root of an argument.
In the following statement, Teradata Database implicitly converts the
character argument to FLOAT type
SELECT SQRT('13147688');
CAST in Explicit Data Type Conversions
Purpose
Converts an expression of a given data type to a different data type or the same data type with
a different format.
Teradata SQL supports two different syntaxes for CAST functionality, only one of which is
ANSI SQL-2003-compliant.
Syntax
----CAST---- (expression----AS---- ansi_sql_data_type------)
data_type_list
Expression
an expression with known data type to be cast as a different data
type.
ansi_sql_data_type
the new data type for expression.
data_type_list
the new data type or data attributes or both for expression.
117
117
CAST does not convert the following data type pairs:
Numeric to character, if the server character set is GRAPHIC.
Character expressions having different server character sets.
Teradata Conversion Syntax in Explicit Data
Type Conversions
Teradata conversion syntax is defined as follows
---expression------(data_type_list)------
Expression
The data expression to be converted to the new definition defined by data_type_list
Data_type_list
A data type declaration or data attributes or both.List elements must be separated
by commas.