0% found this document useful (0 votes)
79 views3 pages

Teradata SQL Quick Reference Guide: Simplicity by Design, Second Edition

This document provides a quick reference guide for Teradata SQL functions including HELP, SHOW, EXPLAIN, and user information functions. HELP returns information about database objects. SHOW returns the DDL for objects. EXPLAIN returns the query execution plan. User information functions like DATABASE change the current database, and SESSION returns the current session number.

Uploaded by

dharmendard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views3 pages

Teradata SQL Quick Reference Guide: Simplicity by Design, Second Edition

This document provides a quick reference guide for Teradata SQL functions including HELP, SHOW, EXPLAIN, and user information functions. HELP returns information about database objects. SHOW returns the DDL for objects. EXPLAIN returns the query execution plan. User information functions like DATABASE change the current database, and SESSION returns the current session number.

Uploaded by

dharmendard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Teradata SQL Quick Reference Guide: Simplicity by Design, Second

Edition
by Tom Coffing, Michael Larkins and Steve Wilmes
Coffing Data Warehousing. (c) 2006. Copying Prohibited.

Reprinted for Chandrasekhar Marisetti, IBM


[email protected]
Reprinted with permission as a subscription benefit of Books24x7,
http://www.books24x7.com/

All rights reserved. Reproduction and/or distribution in whole or in part in electronic,paper or


other forms without written permission is prohibited.

TeradataSQLQuickReferenceGuide:SimplicitybyDesign,SecondEdition

Help, Show, Explain, User Information Functions


HELP
The Help Function returns important information regarding the object specified in the SQL. Results include columns involved in the object,
the data type, parameters passed, table and column comments, etc.
HELP <OBJECT> <Object Name>;
Object Choices:
Database

User

Table

Volatile Table

View

Macro

Procedure

Trigger

Column

Index

Statistics

Session

HELP Database SQL_CLASS;

HELP Table SQL_CLASS.Student_Table;

HELP Column

Course_Table.Course_Name;

HELP Session;
HELP 'SQL | <Function>';
HELP 'SQL Create';

HELP 'SQL Explain';


Issues:

A common problem is that an object does not exist. Object <object-name> does not exist.

Solutions:

The easiest and quickest solution is to execute the HELP DATABASE <database-name> command to see what objects are in the database. You
might have misspelled the object name or are pointing to the wrong database. The HELP SESSION command will tell you what Database you are
currently in.

SHOW
Teradata will return the actual DDL/Create Text for the given object in the SQL. This is handy if a user needs to create an object identical or
similar in structure. You can also use this to see what indexes are on a table.
SHOW <OBJECT> <object name>;
Object Choices:
Table

View

Macro

Trigger

Procedure

SHOW Table Department_Table;

SHOW View Department_Table_v;

SHOW Macro SQL_CLASS.Department_Count_m;

SHOW Trigger Update_Department_t;

SHOW Procedure Department_Count_p;


Issues:

Object does not exist error code: <object-type> <object-name> does not exist.

Page 2 / 3
Reprintedforibm\[email protected],IBM

CoffingDataWarehousing,CoffingPublishing(c)2006,CopyingProhibited

TeradataSQLQuickReferenceGuide:SimplicitybyDesign,SecondEdition

Solutions:

The first item is to check the spelling of the <object-name> to ensure proper spelling. The next choice is to simply run the HELP DATABASE
<database-name> command to get a list of all the objects in the database where you believe the object is located. You can also see which database
you are currently point to with the HELP SESSION command.

Hint - Man The SHOW command is great if you want to see columns definitions, what indexes are defined, and any constraints in the
table. If you have to change a view, macro, or stored procedure with the replace command it is a great idea to do the show
command and then copy the current structure to make the necessary changes.

EXPLAIN
Returns the Optimizer's plan of how the Teradata system will perform the given SQL request. This plan will include information on indexes
being used, estimated time for query execution, estimated range of rows returned, and information about the spool space used during the
query.
EXPLAIN <SQL command>;

EXPLAIN
SELECT * FROM Student_Course_Table;

EXPLAIN
SELECT last_name, first_name
FROM Employee_Table
WHERE Salary > 45000;

EXPLAIN
SELECT Customer_Number, Customer_Name
FROM Customer_Table AS a INNER JOIN Order_Table AS b
ON a.customer_number = b.customer_number;
Hint - Man It is always recommended to run an EXPLAIN on any new query involving large tables, or vital tables that are frequently
accessed. The EXPLAIN will also tell you the strategy for joins or the indexes being utilized for a particular query.

User Information Functions


Default Database Command
Moves the scope of the user from one database to <Database Name>. This command can eliminate the need to qualify a table in a certain
database.
Database <Database Name>;
DATABASE SQL_CLASS;
Account
Returns the account number for the current user you are logged in as.
Select ACCOUNT;
SELECT Database Command
This command displays the database that the user is currently located.
Select DATABASE;
SESSION
Retrieves the session number about the current user.
Select SESSION;

Page 3 / 3
Reprintedforibm\[email protected],IBM

CoffingDataWarehousing,CoffingPublishing(c)2006,CopyingProhibited

You might also like