You are on page 1of 8

Teradata information

Page 1 of 8

More

Next Blog

Create Blog

Sign In

Teradata information
Followers

Tuesday, September 16, 2008

with Google Friend Connect

Members (4)

caliculate permspace taken by a


table in teradata
To find total permanent space taken by a table on all AMPs.
select databasename, tablename, sum(currentperm)
from dbc.tablesize where databasename = 'nv185003'
and tablename = 'testing' group by databasename ,
tablename;

Already a member? Sign in

DataBaseName TableName Sum(CurrentPerm)


---------------- ------------ ------------------nv185003 testing 1,536

here 'testing' is the table name and nv185003 is the user/database


name.
To find total permanent space taken by a table on each AMP.

This page cant be displayed


select databasename, tablename, currentperm,Vproc
from dbc.tablesize where databasename ='nv185003'
and tablename = 'testing' ;

My Search Engine

DataBaseName TableName Sum(CurrentPerm) Vproc


---------------- ------------ ------------------- -----nv185003 testing 1,024 0
nv185003 testing 512 1

Search

Is this blog
content useful?

Posted by NAGARAJU VARAPARLA at 9:51 AM No comments:

getting count of data from n


different tables in teradata
I have n tables .
all tables need not to have
1.same number of columns
2.common columns.

Hello

I need to get the count of the data which is union of all the table's
data.
for example there are 3 tables a,b,c in which
table 'a' has 3 rows
table 'b' has 4 rows.
table 'c' has 5 rows.

Welcome To World of Teradata

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Blog Archive
2008 (9)
September (9)
caliculate permspace taken by a
table in teradata
getting count of data from n
different tables in t...
To get syntax for a command in
teradata
Teradata - Permanent Space VS
Temporary Space VS S...
Concept of Primary Key and
Primary Index in Terada...
How do i update multiple rows of
a table in a sing...
select TOP n row(s) from a table.
How to display Date in 'YY-MM-dd'
format in Sql As...
Global Temporary Tables and
Volatile Temporary Tab...

About Me
NAGARAJU VARAPARLA
hyderabad, Andhra Pradesh, India
Software Engineer with Teradata
View my complete profile

Page 2 of 8

then Result Should be Count of a + Count of b + Count of c


(i.e) 3+4+5 = 12
Ans :
I am doing this by taking 3 tables as example.
we can extend this for any number tables;
select * from a;
*** Query completed. 3 rows found. One column returned.
*** Total elapsed time was 1 second.
col1
----------3
1
2
select * from b;
*** Query completed. 4 rows found. 2 columns returned.
*** Total elapsed time was 1 second.
col1 col2
----------- ----------33
11
44
22

select * from c;
*** Query completed. 5 rows found. 3 columns returned.
*** Total elapsed time was 1 second.
col1 col2 col3
----------- ----------- ----------555
333
111
444
222

SELECT
(
SELECT
UNION
SELECT
UNION
SELECT
)t;

SUM(CountTables) FROM
COUNT(*) AS "CountTables" FROM a
COUNT(*) AS "CountTables" FROM b
COUNT(*) AS "CountTables" FROM c

*** Query completed. One row found. One column returned.


*** Total elapsed time was 1 second.
Sum(CountTables)
---------------12
Posted by NAGARAJU VARAPARLA at 8:07 AM No comments:

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Page 3 of 8

To get syntax for a command in


teradata
After logging on to teradata through bteq/Sql assistant
type the following command

exec dbc.getsyntax('sql','create table');


getsyntax is a macro that accepts 2 parameters.
First parameter is the type of utility that the command
belongs to.
valid values includes the following.
PMPC

BULKLOAD
DUMP
ARCHIVE
MULTILOAD
VERSION
SPL
FASTEXPORT
DATA_TYPE
HELP
SQL
FASTLOAD
TPCCONS
Second parameter the command name for which we need to find the
syntax.
examples includes:
exec dbc.getsyntax('FASTLOAD','DEFINE');
exec dbc.getsyntax('MULTILOAD','.IMPORT');
exec dbc.getsyntax('SQL','UPDATE');
Posted by NAGARAJU VARAPARLA at 4:09 AM No comments:
Labels: getsyntax

Teradata - Permanent Space VS


Temporary Space VS Spool Space
Teradata space usage:
---------------------3 kinds of Space(s) in Teradata database:
1. Permanent Space
2. Spool Space
3. Temporary Space
Example: create user xyz perm = 1e4, spool = 1e3, temporary = 1e3,
password = xyz;
-> Permanent space is used for database object (tables, indexes
etc) creation and to hold their data.

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Page 4 of 8

-> Spool space is used to hold data for Intermediate Query results.
Holds only data.
Active upto the current session only.
Spool space is same as that of the root, unless specified.
-> Temporary Space is used to store Global temporary tables data.
Data is active upto the current session only.

5 kinds of Tables in Teradata database:


1.
2.
3.
4.
5.

SET Table
Multiset Table
Global Temporary Table (GTT)
Temporary Table
Volatile Temporary Table

Create tables go into data dictionary (Permament Space)


Tables
-----SET table:
----------
1. Table defintion : In data dictionary (permanent space)
2. Data storage : Permanent space
3. After Database restart: Both table and data survives
4. Example : Can directly create with 'create set table .'
5. Collect stats : Yes
Mutliset table:
--------------1. Table defintion : In data dictionary (permanent space)
2. Data storage : Permanent space
3. After Database restart: Both table and data survives
4. Example : Can directly create with 'create multiset
table .'
5. Collect stats : Yes
Global Temporary Table(GTT):
---------------------------1. Table defintion : In data dictionary (permanent space)
2. Data storage : Temporary space
3. After Database restart: Table definition survives
4. Example : Can directly create with 'create global
temporary table .'
5. Collect stats : Yes
Temporary Table:
---------------------------1. Table defintion : No table definition
2. Data storage : Spool
3. After Database restart: Nothing survives
4. Example : Indirectly ( derived tables )
5. Collect stats : No
Volatile Table:
---------------------------1. Table defintion : System Cache (primary memory - RAM)
2. Data storage : Spool
3. After Database restart: Nothing survives
4. Example : Indirectly ( derived tables )

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Page 5 of 8

5. Collect stats : No
Posted by NAGARAJU VARAPARLA at 3:53 AM 2 comments:

Saturday, September 13, 2008

Concept of Primary Key and Primary


Index in Teradata
In Teradata,
Primary key is used to uniquely identify each row in a table.PKs are
used in conjunction with foreign keys to define the important
column relationships in a database.
The concept of primary index is completely different from that of
Primary key.
Primary Index is used to distribute and locate rows of a table over
the AMPS .Choice of Primary Index will affect distribution ,access
and performance.
Oftentimes, but not always, the Primary Index and Primary Key are
the same.
Indexes (primary or secondary) may be used to enforce uniqueness
(as in a PK) or to improve access.
Accessing rows using primary index is always one AMP operation.
PK is a relational modeling convention where as PI is a teradata
convention.

Example to create a table with Unique Primary Index (UPI) :


CREATE TABLE MJ1.emp_data,FALLBACK,
NO BEFORE JOURNAL,
NO AFTER JOURNAL
(
employee_number INTEGER NOT NULL,
department_number SMALLINT,
job_code INTEGER COMPRESS ,
last_name CHAR(20) NOT CASESPECIFIC NOT NULL,
first_name VARCHAR(20) NOT CASESPECIFIC,
street_address VARCHAR(30) NOT CASESPECIFIC TITLE 'Address',
city CHAR(15) NOT CASESPECIFIC DEFAULT 'Boise'
COMPRESS 'Boise',
state CHAR(2) NOT CASESPECIFIC DEFAULT ' ',
birthdate DATE FORMAT 'mm/dd/yyyy',
salary_amount DECIMAL(10,2),
sex CHAR(1) UPPERCASE NOT CASESPECIFIC)
UNIQUE PRIMARY INDEX ( employee_number )
INDEX ( department_number );

Features of Primary Key :


if PI is not explicitly specified ,The database selects a Primary index
based on the following choices.

http://nagarajuvaraparla.blogspot.in/

PI Specified

IF ..

THEN.

No

PK specified?

PK = UPI

10-03-2015

Teradata information

Page 6 of 8

Yes

UNIQUE specified?

1st UNIQUE = UPI

Neither specified?

1st column = NUPI

PK specified?

PK = USI

UNIQUE specified?

UNIQUE = USI

Here is the Comparison b/n Primary Key and Primary Index.

Primary Key

Primary Index

Logical concept of data modeling.

Physical mechanism for acc

storageTeradata doesnt need to recognize

Each table must have exac


index.

No limit on number of columns

16 column limit (V2R4.1);


(V2R5)

Documented in data model

Defined in CREATE TABLE s

(Optional in CREATE TABLE)


Must be unique

May be unique or non-uniq

Identifies each row

May be unique or non-uniq

Values should not change

Values may be changed (D

May not be NULL requires a value

May be NULL

Does not imply an access path

Defines most efficient acce

Chosen for logical correctness

Chosen for physical perform

Posted by NAGARAJU VARAPARLA at 9:07 PM No comments:

How do i update multiple rows of a


table in a single query??
select * from tab1;
*** Query completed. 2 rows found. 2 columns returned.
*** Total elapsed time was 1 second.
col1 col2

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Page 7 of 8

----------- ---------101 vij


102 ven
UPDATE tab1
SET col2 = CASE WHEN col1 = 101 THEN 'XXXX'
WHEN col1 = 102 THEN 'YYYY'
END;
select * from tab1;
*** Query completed. 2 rows found. 2 columns returned.
*** Total elapsed time was 1 second.
col1 col2
----------- ---------101 XXXX
102 YYYY
Posted by NAGARAJU VARAPARLA at 4:37 AM No comments:

select TOP n row(s) from a table.


At the start the table contains the following rows.
select * from tab7 order by 1;
col1 col2
----------- ----------1
2
3
4
5
6

2
2
2
4
5
6

Problem:
To Get 2nd row from the bottom.
select * from tab7 QUALIFY RANK(col1) =2;
col1 col2
----------- ----------55

To Get Top 2nd row :


select * from tab7 QUALIFY RANK(col1 ASC) =2;
col1 col2
----------- ----------22

To Get Top 4 rows :


select * from dup_tab1 QUALIFY RANK(col1 ASC) <= 4;
To Get Top 4 rows randomly :
select TOP 10 * from dup_tab1;

http://nagarajuvaraparla.blogspot.in/

10-03-2015

Teradata information

Page 8 of 8

Posted by NAGARAJU VARAPARLA at 4:13 AM No comments:

Home

Older Posts

Subscribe to: Posts (Atom)

http://nagarajuvaraparla.blogspot.in/

10-03-2015

You might also like