Вы находитесь на странице: 1из 16

DAY-1

Parallel aware optimizer - provides all possible access paths Matured optimizer - select best possible path out of all possible access paths

Oracle shared-everything architecture, teradata is shared-nothing LDM - Logical data model PDM - Physical data model

DW is a S-ubject oriented I-ntegrated N-on volatile T-ime variant A-rchived

PE - Parsing Engine AMP - Access Module Process SMP - Symmetric Multi-Processor MPP - Massively Parallel Processing

TDPID - Teradata Director Processor ID

Teradata version = V2R4, V2R5, V2R6, V2R12 Latest is V2R13

Teradata Operators 1.Wildcard operator - %, _ 2.concatenation operator - || 3.Arithmatic Operator : +, -, *, / , Mod 4.Logical Operator - EQ, NE, LT, GT, LE, GE 5.Relational Operator - AND, OIR, NOT 6.set Operator - Union (selects unique records), Union All (gives everything including duplicate records), Intersect, Minus (Except)

DAY-2
Connecting to command interface command interface - go to run -> type bteqwin .logon Demotdat/DBC DBC Connect to database -> database <database name>; eg. database financial;

C:\Windows\System32\drivers\etc (host file location)

********Teradata Table Naming conventions -******************* 1. Maximum 30 chars for table name 2. A-Z, 0-9, #, $, -

********Teradata Extensions for commands-*********** Select -> Sel Insert -> Ins

Update -> Upd Delete -> Del create table-> ct create view -> cv

********Different types of tables in Teradata*********** Two types of tables 1. Set table - Doesnot allow insertion of duplicate records. syntaxCreate table E11 (empno integer, ename char(10), sal integer); 2. Multiset table - Allow duplicate records to be inserted in the table. syntax Create multiset table E12 (empno integer, ename char(10), sal integer); note - Table can have upto 2048 columns

Teradata extension to sql commands Help help database <database name> -> gives database descrtiption all tables listed "Kind" column in output of above commannd can have following values - T (Table), V (View), G (Trigger), M (Macro), I (Index), P (Procedure) help table <tablename> - describe table help column <tablename.columnname> -> give details of specific column help session -> gives details of currently logged in user help index <tablename> -> gives list of all index table have

help statistics <tablename> -- gives details of statistics collected on table Show show table <tablename> - gives the DDL for the table "Type" column in output of above command can have following values - CF (Character Fixed), CV (Character Variable), D (Decimal), DA (Date), I (Integer), I1 (Byte Integer), I2 (Small Integer) Use Byte Intereget : If value is between -128 to 127 Small Integer : If value is between -32768 to 32767 Show macro <macro name> - Show the macro defination.

Extract - extract component of date like year, month, day, hour, minutes, seconds eg. select cust_id,acct_start_date,extract(day from(acct_start_date)) from accts Quantifiers - Any, Some, All Gives all records with lst_names that have any of 'a' and 'b' select * from customer_name where last_name like Any ('%a%','%b%') 'some' is similar to Any Gives all records with lst_names that have both 'a' and 'b' select * from customer_name where last_name like ALL ('%a%','%b%') Escape Sequence Gives all records for which first_name contains '_' character. select * from customer_name where first_name like '%/_%' escape '/'

Case specific - If column ename is not defined as case specific. select * from A1 where ename (cs) like 'ram' - query will match the case for ename

select * from A1 where ename like 'ram' - query will not match case

What are the Modes of Teradata :

BTET (Begin Transaction End Transaction) Mode (Defualt mode) : In


BTET mode transactions all automatically commited.

ANSI Mode : In ANSI mode Commit has to be specified explicitly. To set


to ANSI mode use below command in BETQ window. To change the mode close the BETQ window and start again. .set session transaction ANSI;

--select e.empno,e.ename,a.address from e,a where e.empno = a.empno --select e.empno,e.ename,a.address from e inner join a on e.empno = a.empno --select e.empno,e.ename,a.address from e left outer join a on e.empno = a.empno --select coalesce(e.empno,a.empno),e.ename,a.address from e full outer join a on e.empno = a.empno

Column level attributes Default (use default value defined for specific column) / With Default (use default value defined at data type level) Title - Change the display name of the column Uppercase - convert column value to uppercase Compress - It will internally store the values in a compressed from to save space. List of values to be compressed can be defined at the time of table creation. maximum of 255 values can be compressed. Null values cab also be compressed. e.g. ct C2 (empno integer,city char(10) compress('Mumbai','Chennai','Haryana')); compressed values will appear as normal in result. Only difference is how they are stored internally in database.

DAY-3
Teradata Indexes upto 64 cols can be combined to form a index A single table can have upto 32 secondary indexes. A table can and must have only one primary index. Type of Indexes Primary Index Unique Primary Index Non-Unique Primary Index Secondary Index Unique Secondary Index Non-Unique Secondary Index

Teradata Maximum node = 2048 columns in a table = 2048 primary index = 1 secondary index = 32 columns in index = 64 Primary Index Partitions in one AMP= 65535 table can have constraints = 100 refrential integrity constraints in table = 64 maximum join conditions = 64 Journals per database = 1 maximum values that can be compressed for a columns = 255

Load utilities FastLoad : Load a flat file into empty teradata table. Table level lock applied. syntax : fastload < <file location> Multiload : Load a flat file into an existing teradata table (may be empty or populated). It will do UPSERT (Update insert). New records loaded, existing records updated. Table level lock. FastExport : Export records from teradata database to a flat file. Tpump : Import data from flat file into teradata database. Row level locking used. Update rate can be controlled by specifying how many update to be made per minute. Bteq : any custom script

Partition Primary Index Cases Case-1 CREATE SET TABLE FINANCIAL.PPI2 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( cust_id INTEGER NOT NULL, acct_type CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_nbr CHAR(16) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_start_date DATE FORMAT 'YYYYMMDD' NOT NULL, acct_end_date DATE FORMAT 'YYYYMMDD', dept_no integer) UNIQUE PRIMARY INDEX (cust_id) partition by cust_id;

Case-2 CREATE SET TABLE FINANCIAL.PPI2 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( cust_id INTEGER NOT NULL, acct_type CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_nbr CHAR(16) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_start_date DATE FORMAT 'YYYYMMDD' NOT NULL, acct_end_date DATE FORMAT 'YYYYMMDD', dept_no integer) PRIMARY INDEX (cust_id) partition by dept_no; Case-3 CREATE SET TABLE FINANCIAL.PPI3 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( cust_id INTEGER NOT NULL, acct_type CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_nbr CHAR(16) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_start_date DATE FORMAT 'YYYYMMDD' NOT NULL, acct_end_date DATE FORMAT 'YYYYMMDD', dept_no integer) UNIQUE PRIMARY INDEX (cust_id, dept_no) partition by dept_no;

Case-4

CREATE SET TABLE FINANCIAL.PPI4 ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL ( cust_id INTEGER NOT NULL, acct_type CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_nbr CHAR(16) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL, acct_start_date DATE FORMAT 'YYYYMMDD' NOT NULL, acct_end_date DATE FORMAT 'YYYYMMDD', dept_no integer) PRIMARY INDEX (cust_id) partition by cust_id;

Empno UPI, PPI NUPI PPI

Deptno

Index Allowed Allowed Allowed Allowed

Empno and Deptno are combined UPI, Deptno is PPI NUPI,PPI UPI PPI

Not Allowed

Teradata V13 - What's New? MLPPI - Multi Level Partition Primary Index Multi level partition means having partitions inside partition. maximum 15 levels of partitions is possible. eg. First partion Country, inside it state, inside it city Teradata V13 allows a table to be created without Primary Index

Rankselect cust_id,income,rank(income) from customer_name qualify

rank(income) lt 5 cust_id 1362500 1362489 1362551 1362650 56708 55888 23085 17804 income 1 2 3 4 rank(income)

Creating table from existing table Without data create table accts2 as (select * from accts) with no data With All Data create table accts2 as (select * from accts) with data; With selective data create table accts3 as (select * from accts where cust_id=1362503) with data;

Macro for inserting/updating into table


Create set table salary(eid integer,esal integer) unique primary index (eid); Create macro salary_merge(eid int, esal int) as ( mergeinto salary using values(:eid,:esal) as salary_temp(eid,esal) ON salary.eid =salary_temp.eid when matched then update set esal=salary_temp.esal when not matched then insert values (salary_temp.eid, salary_temp.esal);); To import a file and do insert update using above macro follow beow stepsEnable import option in file menu. Execute the macro with all parameters as '?' e.g Execute salary_merge(?,?);

Macro to validate input parameter Create macro m_age(age integer) as ( rollback work 'invalid age' where :age < 21; select * from customer where age = :age;);

Day-4
Types of Temporary Tables
Derived Table - local to the query only. Memory allocated in spool space. Volatile Table - local to the session. As soon as user logout table is removed from spool space. create volatile table vt1(empno integer, ename char(10)); --on commit rows will be deleted from the table create volatile table vt2(empno integer, ename char(10)) on commit preserve rows; --rows will remain in the tableafter commit. Global Temporary Table - Temporary table defined to be used by all the users. located in temp space and also defination included in data dictionary. create global temporary table vt3(empno integer, ename char(10)); create global temporary table vt3(empno integer, ename char(10)) on commit preserve rows;

Join Index Join index is stored as a table containing the result of join operation. Everytime same join query is executed result is fetched from join index. Any changes made to base tables used in join query is automatically reflected in join index.

Creating Join Index

create join index ji_customer as

select (a.cust_id,a.acct_type,a.acct_nbr),(c.income,c.age,c.gender) from customer c inner join accts a on a.cust_id = c.cust_id primary index (cust_id); once the join index is defined below query will fetch results from join index only and will not join two tables. If one more extra column is added to join query (which is not originally a part of join index) it will not join join index select a.cust_id,a.acct_type,a.acct_nbr,c.income,c.age,c.gender from customer c inner join accts a on a.cust_id = c.cust_id

Explain -

explain command gives the detailed execution plan for a query.

syntax -: EXPLAIN <query> e.g. Explain select a.cust_id,a.acct_type,a.acct_nbr,c.income,c.age,c.gender,c.marital_status from customer c inner join accts a on a.cust_id = c.cust_id

Collecting Statistics
Query to Collect stats of table Syntax : Collect statistics on <table name> index (<indexed columns>) Collect statistics on accts index (cust_id,acct_type) --on index column(s) Syntax : Collect statistics on <table name> column (<columns>) Collect statistics on accts column (acct_end_date) --on non index column(s) drop statistics on <tablename> Help statistics accts --gives details of statistics collected on table

Main data dictionary tables


DBC.AccessRights, DBC.DataBases, DBC.Indexes, DBC.TVM, DBC.Users,

Protections
Transient Journal RAID Fallback Fallback Cluster Recovery Journals Permanent Journals Clique Archive

Identity :
It is used to auto generate values for columns. Similar to sequence generator. create table K1(empno integer generated always as identity(start with 1 increment by 1), ename varchar(20))

Handling NULL/Zero in query


NullIfZero (variable) : Values will be replaced by Null if Zero. Usefull in
calulations where divide by zero can occur.

ZeroIfNull (variable) : Value will be replaced by Zero if Null. Usefull


when adding two values and any of the value can be null.

NullIf (variablename,value) : return null if variable equal to the given


value.

Parralelism in Teradata Multi AMP Multi Step Multi Statement

Teradata Parallel Transporter

Starting DBA App: type winddi in run

Queries. --help database financial --help table emp --show table E11 --select * from customer where age in (20,21)

--ct E13 (empno integer, ename char(10), sal integer); --insert into E12 values('101','A',1002); --select * from e12; --help session --select * from E11 --union all select * from e12; --alter table e11 add(dob date) --update e11 set dob=19820714 where sal=1000

--update e11 set dob=820714 where sal=1002

--select cust_id,acct_start_date,extract(day from(acct_start_date)) from accts --show table customer_name --create table A1 (empno integer, ename varchar(10)) --insert into A1 values (102,'ram') --select * from A1 --show table A1 --select * from e11 --where ename (cs) like 'ram'

--select cust_id, acct_start_date, acct_start_date (format 'mmmbbddbbyyyy') from accts

--ct A (empno integer, address char(30)) --insert into A values(104,'Srinagar')

--select e.empno,e.ename,a.address from e,a where e.empno = a.empno --select e.empno,e.ename,a.address from e inner join a on e.empno = a.empno --select e.empno,e.ename,a.address from e left outer join a on e.empno = a.empno --select coalesce(e.empno,a.empno),e.ename,a.address from e full outer join a on e.empno = a.empno --select gender,count(1) group by gender from customer --select * from customer where income gt (select avg(income) from customer) order by income

--show table customer

--create table E10(empno integer not null, user_name char(15) default user,last_name char(15) with default,street_address varchar(10) title 'Address', gender char(1) Uppercase); --show table C2 --select * from e10; --insert into E10 values(102,,,'Delhi','f') --ct C1 (empno integer,city char(10) compress 'Mumbai'); --ct C2 (empno integer,city char(10) compress('Mumbai','Chennai','Haryana')); --show table C1 --insert into C1 values(100,'Mumbai'); --select * from C1

--select * from customer_name where last_name like some ('%a%','%b%') --update customer_name set first_name='Twin_kle' where cust_id=1362605 select * from customer_name where first_name like '%/_%' escape '/'

Вам также может понравиться