Date post: | 01-Oct-2015 |
Category: |
Documents |
Upload: | bada-sainath |
View: | 12 times |
Download: | 0 times |
TERADATAIntroduction: -
The teradata is a relational data base management system which is specially designed to build an enterprise DWH.
The teradata uses parallelism to store (or) manage tera bytes of business data.
The teradata supports massively parallel processing with shared nothing architecture.
A teradata is required to build decision supporting system.
Teradata supports to run on windows and UNIX operating systems.
Teradata has unlimited parallelism with unlimited scalability. It makes teradata worse time data base to build Decision Supporting System (DSS).COMPUTING ARCHITECTURES: -
There are two scalable hardwares that can processes and manages the data
i. SMP (Symmetric Multi Processor (or) Shared Memory Processor)
ii. MPP (Massively Parallel Processor)
Symmetric Multi Processor (SMP): -
Its a shared memory architect. Limited parallelism up to 64 processors. Limited scalability up to 64 processors.
MASSIVELY PARALLEL PROCESSOR (MPP): -
Unlimited parallelism
Unlimited scalability
Linear expendability
Integration of hundreds and thousands of uni processors
Massively parallel processing with shared nothing architect
Linear parallelism
Ex: - Tera data, Metezza, Green plum (all are data bases)
Data stage (ETL Tool)
TERADATA SERVER ARCHITECTURE: -Teradata Client: -
A Teradata client is an application that allows you to prepare SQL request.
There are two teradata queries submitting utilities.i. Teradata SQL Assistant
ii. BTEQ (Basic Teradata Query)
COMPONENTS & ARCHITECTURE: -
Parsing Engine: -
A parsing engine is made up of following software components
i. Parser
ii. Optimizer
iii. DispatcherParser: -
It performs the following activities when the request is received from the client
I. It validates the users access right to the objects.II. It interprets the SQL into the machine language.III. Validates the SQL query for a syntactical check.
Optimizer: -The optimized role is to prepare least expensive query execution plan.
Least expensive is measured in terms of system resource usage.
Dispatcher: -The dispatcher dispatches the query execution plan to the messaging passing layer (network).MESSAGE PASSING LAYER (MPL): -
The message passing layer manages the dialogues between parsing engine access module processor (AMP).
It makes teradata parallelism possible.
Merging the answers-sets back to the parsing engine.
The message passing layer is a combination of
a. BYNET Software
b. BYNET Hardware for MPP
c. Parallel data base extensions softwareACCESS MODULE PROCESSORS: -
It processes the SQL requests.
Access Module Processor stores and retrieve rows to and from disks.
Access Module Processor performs the following tasks
1. Finding the rows requested
2. Lock management
3. Accounting
4. Recovery processing
5. Sorting the rows
6. Aggregating the rows
7. Joining the data
8. Output conversions
9. Creating Answers-sets for client
VIRUTIAL DISK (V-Disk): -
It is a combination of inter connected physical storage units.
Each AMP manages portion of total data
TERADATA COMPITITIVE ADVANTAGES: -
Scalability: -
This is the only RDBMS which confirms the performance improvement by adding more hardware.
Maintenance: -
When you add hardware the data gets distributed automatically.
Massively Parallel Processing: -
It works based on massively parallel processing architecture.
Shared Nothing Architecture: -
Using special software and hardware components, teradata gets the data faster.
Mature Optimizer: -
It handles complex queries up to 64 joins per query.
Unlimited Parallelism: -
It can add hundreds and thousands of processors to achieve the linear parallelism.It provides a single version of business.
Low CTO (Total Cost of Ownership): -Ease of setup, maintenance, administration expansion.
Parallel Load and Unload Utilities: -Robust, parallel and scalable load and unload utilities such as BTEQ, Fast load, Multi Load, T-pump and Fast Export.
TERADATA INSTALLATION PROCEDURE: -
Click on SETUP Click on Main Menu
Click on Install Teradata Express
Click on Installation Menu
Install the following components one after the other
i. Teradata BYNET Driver
ii. Teradata Database
iii. Teradata Express Tools
iv. Teradata Tools and Utilities
v. Teradata Warehouse Miner
CREATION ODBC CONNECTIONS: -Start settings ( Control Panel (Administrative Tools ( Data Sources (ODBCS) Select a system DSN
Click on add
Select a driver Teradata
Click on Finish
Enter the following details
Name: - TD_USER {our wish}
IP address: - 127.0.0.1 {for local system}
User Name: - TDUSER
Password: - TDUSER
Click OK.TERADATA INDEXES: -Indexes are used to access rows from a table without having to search the whole table. In the teradata RDBMS, an index is made up of one (or) more columns in a table. Once teradata indexes are selected they are maintained by the system.
In the Teradata RDBMS, there are two types of indexes
Primary indexes define the way the data is distributed.
Primary indexes and Secondary indexes are used to locate the data rows more efficiency than searching the whole table.
PRIMARY INDEXES: -
When the primary indexes for the table is well chosen the table rows are evenly distributed across the multiple AMPs for the best performance.
The primary index is created at the time of creating table.
A primary index created on single column (or) combination of columns.
There are two types of primary indexes,
I. Unique Primary Index
II. Non Unique Primary Index
Note: - Changing the choice of the primary index requires dropping and recreating the table.
UNIQUE PRIMARY INDEX (UPI): -
Syntax: - Create Table Sample_1
(COL A_INTEGER
, COL B_INTEGER
, COL C_INTEGER)
Unique Primary Index (COL_B);
A unique primary index results in distributing the roes very uniform.
Maximum efficiency for parallel operations.
NON-UNIQUE PRIMARY INDEX (NUPI): -Row distribution is less uniform.
** Rows with the same primary index value distributed to the same AMP.
HASH MAP: -A hash map is uniquely configured for each system.
It is an array of 65,536 entries which associates with the specific AMPs.
The system will check for the duplicates unique primary index value on row inserts.A new row is discarded if already row exist with the UPI value.STRUCTURE QUERY LANUAGUE: - (SQL)It is a relational language designed for relational database management system to access and maintains databases.
It is a fourth generation non-procedural set oriented language for relational databases.
The objects in the relational database are created and maintain using relational language.The objects definitions are stored in a data dictionary (or) data directory.
SQL-SUB COMPONENTS: -DATA DEFINTION LANGUAGE (DDL): -The DDL allows the users to define the database objects and create relationship among database objects. (Tables, Views, Triggers, Procedures, Macros)
The following SQL command defines DDL.
SQL StatementFunction
CREATE
DROPALTER It defines a database object (Tables, Views, Procedures, Macros, Triggers (or) Stored Procedure).
It removes a Tables, Views, Procedures, Macros, Triggers (or) Stored Procedure.
It changes a database object definition
DATA MANIPULATION LANGUAGE (DML): -The DML consists of a statement that lets the user to insert, update and delete the data rows of database.
If DDL defines the database the DML lets the user change the information contained in the database.
The DML is the most commonly used sub-set of SQL.
The following commands define DML.
INSERT: - It places a new record into a table.
UPDATE: - It manipulates the data values in one (or) more existing records.
DELETE: - It removes one (or) more rows from table.
DATA RETRIEVEAL LANGUAGE (DRL): -It lets the user to select the data rows from one (or) more tables.
The following command defines DRL
SELECT: - It selects the data from one (or) more tables.
DATA CONTROL LANGUAGE (DCL): -It is used to restrict (or) permit user access to the database
The following commands define DCL.
GRANT: - It gives user privileges on database objects.
REVOKE: - It removes user privileges on database objects.
TERADATA DATABASE: -A teradata database is a group of objects such as Tables, Views, Procedures, Macros, Triggers (or) Stored Procedure.
Every database is created with the following attributes
PERM SPACE: - (Permanent Space) a space which requires to stores the data in the objects such as tables.
TEMP SPACE: - (Temporary Space) a space which requires to temporarily stored the query results (TEMP tables).
SPOOL SPACE: - A space which is required to process user request.
A teradata database is created using CREATE database command.
A database is empty until objects are created.
A teradata administrator creates database using component.Procedure: - (Creation of Database)Start ( Teradata Service
Start ( Programs ( Teradata Administrator
Select the data source TDADIM
Click on OKFrom TOOLS Menu select CREATEClick on DatabaseEnter the Database Name: - SALESEDW (our wish)
Perm Space: - 50MB
Spool Space: - 40MB
Click on CREATETERADATA - USER: -A teradata user is a database with an assigned password.
A teradata user may logon to teradata and access the objects within in itself, can access other databases for which it has access rights.
**A user can access the database using ODBC.
A user is created with following attributes
I. PERM Space
II. SPOOL Space
III. TEMP Space
A user is created using Create User Command.
A user is empty until objects are created.Procedure: - (Creation of User)
Start ( Programs ( Teradata Administrator
Select the data source TDADMIN
Click on OKFrom Tools Menu select CREATEClick on User
Enter the User Name: - BOA (Our Wish)
Password: - BOA
PERM Space: - 50MB
SPOOL Space: - 40MB
Click on CREATEGRANTING PERMISSIONS TO ACCESS OBJECTS: -Procedure: -
From Tools Menu Grant/Revoke
Select Objects Rights
From database select database (BOAEDW)
From Tab TO/FROM USERSelect User: - BOA
Select ALLClick on GRANTClick on CLOSECREATION OF ODBC: -Start ( Settings ( Control Panel ( Administrative Tools ( Data Source ODBC
Select System DSN Tab
Select ADD
Select the drive TeradataClick on FinishName: - BOAEDW_ODBC (Our Wish)
IP Address: - 127.0.0.1
User Name: - BOA
Password: - BOA
Default Database: - BOAEDW
Click on OKCREATION OF INFORMATICA WITH TERADATA: -Source Definition: -
EMP (Oracle)
DEPT (Oracle)
Target Definition: -
EMP (Teradata)
DEPT (Teradata)
Creation of Pass through Mapping
Creation of writer connection using ODBC
Procedure: -
Open the client Power Center Work-flow Manager
From Connections Menu select RelationalSelect the type ODBC
Click on NEW
Enter the following details
Name: - TDUSER
User Name: - TDUSER
Password: - TDUSER
Connect String: - TDUSER
Click on OKCreate on Session
Double click the Session, select the Mapping Tab
From the left window select the Source
Set Reader connection to SCOTTFrom the left window select the Target
Set Writer connection to TDUSER, select the Target load type Normal
From Properties
AttributeValue
Table Name PrefixNIPUNAEDW (Database Name)
Click on APPLY
Click on OKCONSTRAINTS: -Constraints are the Conditions (or) Business Rule defines on one (or) more attributes to variable the values given by the user.If the given values satisfy the condition the database will accept the record else it gets rejected. Teradata supports the following constraints
I. Not Null
II. Unique
III. Primary key
IV. Check
V. Foreign key/ Reference key
NOT NULL CONSTRAINTS: -Create Table DEMO
(EMPNO NUMERIC (4) NOT NULL,
ENAME VARCHAR (10),
SAL NUMERIC (7, 2))
Insert into DEMO values (NULL, SMITH, 800)
Insert into DEMO values (7369, SMITH, 800)
Insert into DEMO values (7489, NULL, 800)
Select * from DEMO
EMPNOENAMESAL
7489?800
7369SMITH800
We can use NULL constraint on any column only when table is created.CHECK CONSTRAINT: -To insert a constraint we use CHECK Constraint.
Syntax: -
ALTER TABLE DEMO
ADD constraint CHK_EN_EN CHECK (ENAME IS NOT NULL)
Update DEMO set ENAME= , where EMPNO=7489
Insert into DEMO values (7521, NULL, 1000)
Insert into DEMO values (7521, WARD, 1000)
To copy the records from one table to other table without NULL command is
Insert into DEMO select * from DEMO;
UNIQUE CONSTRAINT: -Create Table DEMO
(EMPNO NUMERIC (4) UNIQUE,
ENAME VARCHAR (10),SAL NUMERIC (7, 2))
Command does not works without NOT NULL constraint
Create Table DEMO
(EMPNO NUMERIC (4) NOT NULL UNIQUE,
ENAME VARCHAR (10),
SAL NUMERIC (7, 2))
Insert into DEMO values (7521, WARD, 1250)
Insert into DEMO values (7521, SMITH, 1250) ( Record not inserted
Insert into DEMO values (7369, SMITH, 1000)
Insert into DEMO values (NULL, ALLEN, 850) ( Record not inserted
PRIMARY KEY: -To identify a record UNIQELY from a database
Create Table STUD (this table is not create without NOT NULL)
(STNO NUMERIC (3) CONSTRAINT PK_STNO PRIMARY KEY,
SNAME VARCHAR (12),
MKS NUMERIC (13))
Create Table STUD (this is using NOT NULL)
(STNO NUMERIC (3) NOT NULL CONSTRAINT PK_STNO PRIMARY KEY,
SNAME VARCHAR (12),
MKS NUMERIC (3))
Insert into STUD values (5, SMITH, 25)
Insert into STUD values (7, ALLEIN, 50)
Insert into STUD values (NULL, WARD, 40) ( invalid record not Stored
Insert into STUD values (7, WARD, 40) ( invalid record not Stored
Create a Table STUDENT (combination of Secondary (or) Alternate Key)(BCODE VARCHAR (3) NOY NULL,
ROLLNO NUMERIC (3) NOT NULL,
SNAME VARCHAR (10),
MKS NUMERIC (3),
CONSTRAINT PK_BR PRIMARY KEY (BCODE, ROLLNO))
NOTE: -
**NOT NULL can be used in table level
Combination of two Primary Keys is known as SUPER KEYWhen a Constraint is defined at end of database description is called as Table Level Constraint.
When a Constraint is defined at the TOP of database description is called as Column Level Constraint.
Insert into STUDENT values (B1,101, SMITH, 35)
Insert into STUDENT values (B1,102, ALLEIN, 40)
Insert into STUDENT values (B1,103, WARD, 50)
Insert into STUDENT values (B2,101, SMITH, 45)
Insert into STUDENT values (B2,102, ALLEIN, 50)
Insert into STUDENT values (B2,103, WARD, 55)
Insert into STUDENT values (B1,101, STEEVE, 50) ( record not inserted
Create Table DEMO
EMPNO NUMERIC (4) NOT NULL CONSTRAINT PK_ENO PRIMARY KEY,
ENAME VARCHAR (10),
JOB VARCHAR (10),
SAL NUMERIC (7, 2),
CONSTRAINT CHK_SAL CHECK (SAL BETWEEN 2000 AND 5000),
DEPTNO NUMERIC (2))
Insert into STUDENT values (7001, SMITH, CLERK, 800, 20) ( below bound
Insert into STUDENT values (7001, SMITH, CLERK, 800, 20) ( above bound
Insert into STUDENT values (7001, SMITH, CLERK, 4000, 20)
Insert into STUDENT values (7002, ALLEIN, SALESMAN, NULL, 20)
ALTER Table DEMO
ADD CONSTRAINT CHK_SAL_NULL CHECK (SAL is not NULL)
Update DEMO set SAL=2800 where EMPNO=7002
Insert into STUDENT values (7003, SMITH, HYETFJ, 4500, 30)
ALTER Table DEMO
ADD CONSTRAINTS CHK_JOB
CHECK (JOB IN (ANALYST, CLERK, MANAGER, SALESMAN))
Update DEMO set JOB=ANALYST where EMPNO=7003
NOTE: -
Constraint cant be altered, so drop the Constraint and ADD a new constraint with requirement.
Insert into STUDENT values (7005, STELLA, STENO, 2500, 30)
ADD Constraint CHK_JOB
CHECK (JOB IN (ANALYST, SALESMAN, CLERK, MANAGER, STENO))Update DEMO set JOB=STENO, where EMPNO=7005
FOREIGN KEY: -It must relate to a Primary Key (or) Unique.
Create Table DEPT1
(DEPTNO NUMERIC (2) NOT NULL CONSTRAINT PK_DNO PRIMARY KEY,
DNAME VARCHAR (10))
Insert into DEPT1 values (10, ACCOUNTING)
Insert into DEPT1 values (20, RESEARCH)Insert into DEPT1 values (10, SALES)
Create Table EMP1
(EMPNO NUMERIC (4) NOT NULL PRIMARY KEY,
ENAME VARCHAR (10),
SAL NUMERIC (7, 2),
DEPTNO NUMERIC (2)
CONSTRAINT FK_DNO REFERENCES DEPT1 (DEPTNO))Insert into DEPT1 values (7002, ALLEIN, 1500, 40)Insert into EMP1 values (40, OPERATIONS)
Unless child record is not deleted (or) inserted master record is not going to delete (or) insert.JOINS AND TYPES OF JOINS: -A join is a concept in a relational database theory.
A join is a technique for accessing the data from one (or) more tables in a single answer set.
The each row in the answer set contains data from columns of more than one table.
The tables should be join based on Common Column Values.
Joins can be used to make a view of data from more than one table. The following are the types of joins
I. Inner Join (Equi Join)II. Left-Outer Join
III. Right-Outer Join
IV. Full-Outer Join
V. Cross Join
VI. Cartesian Join
VII. Accidental Cartesian Join
VIII. Self Join (Recursive Join)
INNER JOIN: -It combines the data records from multiple tables based on Equality Match.
An Inner Join represents the intersection of the two sets based on common set of values called Join values.
Non ANSI Syntax: -
Select EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.SAL, EMP.DEPTNO, EMP.DNAME, DEPT.LOC from EMP, DEPT where EMP.DEPTNO=DEPT.DEPTNO
ANSI Syntax: -
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E INNER JOIN DEPT D on EMP.DEPTNO=DEPT.DEPTNOEX: - EMP DETAILS DEPT DETAILSEMPNOENAMEJOBSALDEPTNO
1245SIVACLERK500010
1389NARAYANAMANAGER800020
1429SURYACLERK500030
1587NANICLERK500050
DEPTNO
DNAME
LOC
10
SALES
HYD
20
ACCOUNTS
BAN
30
MARKET
CHE
40
OPERATIONS
MUM
Results of Inner Join: -EMPNOENAMEJOBSALDEPTNODNAMELOC
1245SIVACLERK500010SALESHYD
1389NARAYANAMANAGER800020ACCOUNTSBAN
1429SURYACLERK500030MARKETCHE
OUTER JOIN: -An Outer Join forces to combine the records even though there is no Equality Match.
As a result an Outer Join can produce more number of records than Inner Join.
Formulae: -
Outer Join= Inner Join + Non-Matching Records
LEFT OUTER JOIN: -
A Left Outer Join returns Inner Join rows and non-matching rows from Left table.
ANSI Syntax: -
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E LEFT OUTER JOIN DEPT D on EMP.DEPTNO=DEPT.DEPTNOEX: -
EMPNOENAMEJOBSALDEPTNODNAMELOC
1245SIVACLERK500010SALESHYD
1389NARAYANAMANAGER800020ACCOUNTSBAN
1429SURYACLERK500030MARKETCHE
1587NANICLERK500050NULLNULL
RIGHT OUTER JOIN: -
A Right Outer Join returns Inner Join rows and non-matching rows from Left table.
ANSI Syntax: -
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E RIGHT OUTER JOIN DEPT D on EMP.DEPTNO=DEPT.DEPTNOEX: -
EMPNOENAMEJOBSALDEPTNODNAMELOC
1245SIVACLERK500010SALESHYD
1389NARAYANAMANAGER800020ACCOUNTSBAN
1429SURYACLERK500030MARKETCHE
NULLNULLNULLNULL40OPERATIONSMUM
FULL OUTER JOIN: -
A Full Outer Join returns non-matching rows from both tables.
ANSI Syntax: -
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E FULL OUTER JOIN DEPT D on EMP.DEPTNO=DEPT.DEPTNO
EX: -
EMPNOENAMEJOBSALDEPTNODNAMELOC
1245SIVACLERK500010SALESHYD
1389NARAYANAMANAGER800020ACCOUNTSBAN
1429SURYACLERK500030MARKETCHE
1587NANICLERK500050NULLNULL
NULLNULLNULLNULL40OPERATIONSMUM
JOINS USING ALIAS: -An Alias is: -
A temporary name for a table (or) view
Defined in the FROM clause
Useful for abbreviating long table names
Required to join a table to itself CROSS JOIN: -A Cross Join is a join that requires no join condition
Cross joins are sometimes called Product Joins
Each participating row of one table is joined with each participating row of another table
Cross join syntax does not allows ON clauseA WHERE clause may be used to restrict which row participates from either tableANSI Syntax: -
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E CROSS JOIN DEPT D where E.SAL>2000Non-ANSI Syntax: -Select EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.SAL, EMP.DEPTNO, DEPT.DNAME, DEPT.LOC from EMP, DEPT where EMP.SAL>2000
CARTESIAN PRODUCTS: -
A completely unconstrained Cross Join is called a Cartesian product.
Each row of one table is joined to each row of another table.
A Cartesian product results from a Cross Join without a WHERE clause
The output of Cartesian product is rarely meaningful.Cartesian product can also result from an Inner Join with improper Aliasing (or) Join conditions.
Non-ANSI Syntax: -
Select EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.SAL, EMP.DEPTNO, DEPT.DNAME, D.LOC from EMP, DEPT
ACCIDENTAL CARTESIAN PRODUCTS: -A Cartesian product results from an Inner Join with improper aliasing.
Improper Join condition in a Join can result Accidental Cartesian Join.
Non-ANSI Syntax: -
Select EMP.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E FULL INNER JOIN DEPT D on EMP.DEPTNO=DEPT.DEPTNO
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC from EMP E FULL INNER JOIN DEPT D on 3=3
INNER JOIN ON MULTIPLE TABLES: -A Join can have up to 64 participating tables (or) views.
The number of participating tables (or) views determines the number of require Join conditions.
An n-table Join requires n-1 Join conditions.
Omitting a Join condition will result in a Cartesian product Join.SELF JOIN: -A Join which is made on the same table is known as Self Join.
A Self Join is also known as Recursive relationship.
EX: -
Each Employee has a manager, who is also an Employee
Syntax: -Select E.EMPNO as EMP_NUMBER
, E.ENAME AS EMP_NAME
, M.MGR AS MANAGER_NUMBER
, M.ENAME AS MANAGER_NAME
From EMP E JOIN EMP M on E.MGR=M.EMPNO
SET OPERATORS: -The following key words are available as ANSI standard set operators
I. UNION
II. UNION ALL
III. INTERSECT
IV. EXCEPT (MINUS is a NON-ANSI synonym)
UNION: -The Union operator allows combining the two data sets into a single answer set.
The Union set operator eliminates duplicates.
Syntax: -
SELECT * FROM EMP UNION SELECT * FROM EMP;
UNION ALL: -
It allows duplicates in the answer set
Syntax: -( SELCET * FROM EMP UNION ALL SELECT * FROM EMP;
(SELECT * FROM EMP (N) UNION ALL SELECT * FROM EMP WHERE ROWNUM < (N/2+1)
Here N is number of records
INTERSECT: -The Intersect operator captures common content of two data sets into a single answer set.
Syntax: -
CREATE a Table EMP1 as (SELECT * FROM EMP WHERE DEPTNO=20) WITH DATA;
SELECT * FROM EMP INTERSECT SELECT * FROM EMP1;
EXCEPT: -The Except operator produces the difference in contents of the two sets
Syntax: -
CREATE a Table EMP1 as (SELECT * FROM EMP WHERE DEPTNO=20) WITH DATA;
SELECT * FROM EMP EXCEPT SELECT * FROM EMP1;
AGGREGATE FUNCTIONS: -The Aggregation is a process of calculating the summaries for a group of records.
Use the following Aggregate Functions to calculate the summaries (Aggregations)
SUM
AVERAGE
MAX
MIN
COUNT
Syntax: -
i) SELCET DEPTNO, SUM (SAL) FROM EMP GROUP BY DEPTNO ORDER BY DEPTNO
ii) TARGET (DEPTNO, DNAME, SUMSAL)
SELECT EMP.DEPTNO, DEPT.DNAME, SUM (SAL) FROM EMP, DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO GROUP BY EMP.DEPTNO, DEPT.DNAMEThumb Rule: -
If the select statement contains aggregates, other than aggregates appears in Group By clause.
iii) SELECT DEPTNO, JOB, SUM (SAL) FROM EMP GROUP BY 1,2 (DEPTNO, JOB) ORDER BY 1,2 (DEPTNO, JOB)
HAVING CLAUSE: -It is used to make a restriction on summary records
Syntax: -
SELECT DEPTNO, SUM (SAL), MAX (SAL), MIN (SAL), AVG (SAL) FROM EMP GROUP BY DEPTNO ORDER BY DEPTNO HAVING AVG (SAL) > 3000
Some of Conditions without using Sub-Query: -
SELECT * FROM EMP WHERE ENAME=JONES
SELECT * FROM EMP WHERE SAL>2975 {request for finding sal > JONES in the table}
SELECT T1.EMPNO, T1.ENAME, T1.JOB, T1.SAL, T1.DEPTNO FROM EMP T1, EMP T2 WHERE T2.ENAME=JONES AND T1.SAL>T2.SAL
SELECT T1 * FROM EMP T1, EMP T2 WHERE T2.ENAME=JONES AND T1.SAL>T2.SAL
Insert into EMP values (7935, JONES, MANGER, 7839, 17/07/2011, 2000, NULL, 20)
SELECT T1.EMPNO, T1.ENAME, T1.JOB, T1.SAL, T1.DEPTNO FROM EMP T1, EMP T2 WHERE T2.ENAME=JONES AND T1.SAL>T2.SAL ORDER BY {if table contains another employee namely Jones}
CONCEPT OF SUB-QUERY: -When a query is dependent on the output of another query for its predicate (condition) then we use the Sub-queries.A sub-query is a query used in the predicate of another query.
The query which makes use of output written by the sub-query is called Main (or) Parent (or) Route query.
When two (or) more sub-queries are used in the predicate of route query then it is called as multiple sub-queries.
When a sub-query is used in the predicate of another sub-query then it is called as nested sub-query.
Note: -
The sub-query can be on the same table which is used in the main query (or) it can be on any other table of database.
SELECT SAL FROM EMP WHERE ENAME=JONES
SELECT * FROM EMP WHERE SAL>2975
SELECT * FROM EMPWHERE SAL (SELECT SAL FROM EMP WHERE ENAME=JONES)
SELECT * FROM EMP WHERE JOB=(SELECT JOB FROM EMP WHERE ENAME=BLAKE) AND ENAME1=BLAKE
SELECT * FROM EMP WHERE SAL> (SELECT SAL FROM EMP WHERE ENAME=JONES) OR JOB= (SELECT JOB FROM EMP WHERE ENAME=SMITH) {multiple sub-query}
Where a query to find the Employees from DEPTNO=20 whose JOB is same as anyone of the JOB from the DEPT=SALES?
Solution: -
SELECT DEPTNO FROM DEPT WHERE DNAME=SALES
SELECT DISTINCT JOB FROM EMP WHERE DEPTNO=30
SELECT * FROM EMP WHERE DEPTNO=20 AND JOB IN (CLERK, MANGER, SALESMAN)SELECT * FROM EMP WHERE DEPTNO=20 AND JOB IN (SELECT DITINCT JOB FROM EMP) WHERE DEPTNO= (SELECT DEPTNO FROM DEPT WHERE DNAME=SALES)) {nested sub-query}Write a query to find the list of all the employees from DEPTNO=20 whose salary is greater than any one of the salary from the DEPTNO=30? Solution: -
SELECT * FROM EMP WHERE DEPTNO=30 ORDER BY SAL
SELECT * FROM EMP WHERE DEPTNO=20 ORDER BY SAL
SELECT * FROM EMP WHERE DEPTNO=20 AND SAL> (SELECT MIN (SAL) FROM EMP WHERE DEPTNO=30)
SELECT * FROM EMP WHERE DEPTNO=20 AND SAL> (SELECT MAX (SAL) FROM EMP WHERE DEPTNO=30)
SELECT * FROM EMP WHERE DEPTNO=20 AND SAL>ANY (SELECT SAL FROM EMP WHERE DEPTNO=30)
SELECT * FROM EMP WHERE DEPTNO=20 AND SAL>ALL (SELECT SAL FROM EMP WHERE DEPTNO=30)
SELECT * FROM EMP (MAX SAL OF ONE EMPLOYEE) WHERE SAL= (SELECT MAX (SAL) FROM EMP)
SELECT * FROM EMP (MAX SAL OF SECOND SALES)
WHERE SAL= (SELECT MAX (SAL) FROM EMP WHERE SAL< (SELECT MAX (SAL) FROM EMP WHERE SAL> (SELECT MAX (SAL) FROM EMP)))VIEWS: -
A view is like a window into one (or) more tables. It provides customized access to base tables by,
Restricting which columns are visible from base tables
Restricting which rows are visible from base tables
Combining columns and rows from several base tables
A view is virtual table
It may define a subset of row of row of a table
It may define a subset of a table
It may reference more than one table
View definitions are stored in the data dictionary, not in the users own space
Simple View: -
A view which is created from single base table is known as simple view.
A view is created using CREATE VIEW command.
It does not occupy any space because it does not contain any data on its own.
Syntax: -DATABASE SALES
CREATE VIEW V_EMP_TEST AS SELECT * FROM EMP
NOTE: - We can update the base tables (or) you can insert the records into base tables using simple views.
Accessing a record using following command
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE EMPNO=7369;
Updating a base table (view) using following command
UPDATE V_EMP_TEST SET SAL=SAL+100 WHERE EMPNO=7369
Inserting a view a record using following command view to base table
SELECT * FROM V_EMP_TEST (to check record in base table)
INS INTO V_EMP_TEST (EMPNO, ENAME, SAL, DEPTNO) VALUES (8243, SIVA, 4500, 30)
SELECT COUNT (*) FROM EMP (after inserting record)
Complex Views (or) Join Views: -A view which is created from more than one table is known as complex view (or) join view.A join view is a view contains columns from more than one table.
A join condition is a typical part of a view definition.
A join view consists of columns from more than one table.
Warning!
Updating of base tables may not be done via join views
Syntax: -
CREATE VIEW EMP_JOIN_VIEW AS SELECT E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME, D.LOC FROM EMP E INNER JOIN DEPT D ON E.DEPTNO=D.DEPTNO
SELECT * FROM EMP_JOIN_VIEW;
Views to Rename columns: -
You may create a view that renames columns.
This is often used to shorten long column names, making queries easier to create.
Syntax: -
CREATE VIEW EMP_VIEW (ENO, NAME, JOB, SALARY, DNO) AS SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO=30;SELECT * FROM EMP_VIEW;Aggregate Views: -Aggregate views are views which contain aggregate expressions (or) derived columns (scrubbing).
Aggregate and derived columns in the views must be assigned names (Aliases).
Syntax: -
CREATE VIEW V_AGGR AS SELECT DEPTNO, SUM (SAL) AS SUMSAL, AVG (SAL) AS AVGSAL FROM EMP GROUP BY DEPTNO
Join on Views: -Views may participate in join operations just as tables do.
The total number of tables and views which may be used in a single SQL statement is 64.
NON-ANSI Syntax: -
SELECT V.DEPTNO, T.DNAME, V.SUMSAL, V.AVGSAL FROM V_AGGR V, DEPT T WHERE V.DEPTNO=T.DEPTNOANSI Syntax: -SELECT V.DEPTNO, T.DNAME, V.SUMSAL, V.AVGSAL FROM V_AGGR V INNER JOIN DEPT T ON V.DEPTNO=T.DEPTNOView with CHECK Option: -In a view definition, the WITH CHECK Option limits the ability of users with update and inserts privileges on the view.
With the CHECK Option in effect, the user may not update (or) insert rows whose value will violate the constraints of the WHERE CLAUSE in the view definition.
Syntax: -
CREATE VIEW V_EMP_CHECK AS SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL>1500 WITH CHECK OPTION
INSERT Into V_EMP_CHECK Values (2000, SIVA, CLERK, 1200, 10) INSERT Into V_EMP_CHECK Values (2000, SIVA, CLERK, 1500, 10) INSERT Into V_EMP_CHECK Values (2000, SIVA, CLERK, 1501, 10)
Restrictions on Views: -An Index cannot be create on View.
View cannot contain an Order by clause.Derived an Aggregated columns must be assigned a name using AS clause.A view cannot be used for update operations if it contains data from more than one table (Join Views).
A view cannot be used for update operations if it contains derived columns, a distinct clause and Group by clause.
Advantages of Views: -
An additional level of security. Controls read and update privileges. Simplify end users access data. Are unaffected if a column is added to a table. Are unaffected if a column is dropped unless the dropped column is referenced by the view.Suggestions: - Create Views to insure that all users access to tables is via Views.
Create Views which do complex joins (or) Aggregations to simplify end user coding requirements. Use access locks when creating views to maximize data availability to users.
SUB QUERIES: -A query which is defined within the main query is known as sub query.
The sub queries are created to simplify the long list values.
There are two types of sub queries
I. Traditional sub query
II. Correlated sub query
Traditional sub queries: -Traditional sub queries are read from the bottom up. The lowest level query is resolved and the results are fed to the next level of query.
A source statement may reference up to 64 tables (or) Views, thus there may be up to 64 levels of sub query.
Sub query Processing: - Resolve bottom level query first Use results as input to next level
Repeat until top level reached
Syntax: -
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO IN (SELECT DEPTNO FROM DEPT)
DISTINCT ( used for deleting duplicates
RESTRICT( used for finding duplicates
Sub queries in Aggregates: - List out names of employees drawing highest salary
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERESAL= (SELECT MAX (SAL) FROM EMP) List out names of employees drawing salary greater than average salary of company
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL > (SELECT AVG (SAL) FROM EMP)
List out names of employees drawing lowest salary from each companySELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL IN (SELECT MIN (SAL) FROM EMP GROUP BY DEPTNO)
Sub query with WHERE Clause: -
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO = (SELECT DEPTNO FROM EMP WHERE ENAME = MILLER)
Sub query with Qualifier ANY: -
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL > ANY (SELECT SAL FROM EMP WHERE DEPTNO=20)
The teradata server evaluates all the values which are written by the sub query.
Sub query with Qualifier SOME: -
It picks up the lowest value from list of values written by the sub query.
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL > SOME (SELECT SAL FROM EMP WHERE DEPTNO=20)
Correlated Sub queries: -
Correlated sub queries are processed differently from traditional sub queries.
Correlated sub queries expand the functionality of traditional sub queries.
Correlated sub queries are processed using top down approach.
Each row of the outer query is selected and compared to the criteria in the sub query.
When the row matches with the inner query than outer query returns the row.
Usually correlated sub query is sub query whose outer query results are processed as against sub query result.
The sub query result is analyzed for each row of outer query.
Ex: - Find the employees with the highest salary in each department
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP EE WHERE SAL = (SELECT MAX (SAL) FROM EMP EM WHERE EE DEPTNO= EM DEPTNO)Note: - correlated sub queries uses shared spool technique to which makes them correlated sub queries are more fast and efficient.
HELP Utilities: -
Teradata SQL contains extensions beyond ANSI stand SQL.
There are many tools available to provide the Help for a teradata user (or) programmer.
HELP - Command: -
The HELP command provides the help for any defined teradata database object
HELP TABLE
HELP VIEW
HELP MACRO
HELP COLUMN
HELP PROCEDURE etc
SHOW Command: -
The SHOW command displays the data definition (DDL) associates with database objects (Tables, Views, Macros, Triggers, Joins, Indexes, and Stored Procedures).
SHOW command displays how an object was created
COMMANDRETURNS
SHOW TABLE TABLENAME
SHOW VIEW VIEWNAME
SHOW MACRO MACRONAME
SHOW TRIGGER TIRGGERNAME
SHOW JOIN INDEX INDEXNAME
SHOW PROCEDURE PROCEDURENAMECREATE TABLE STATEMENTCREATE VIEW STATEMENT
CREATE MACRO STATEMENT
CREATE TRIGGER STATEMENT
CREATE JOIN INDEX STATEMENT
CREATE PROCEDURE STATEMENT
EXPLAIN Command: -Use an EXPLAIN command to provide query execution plan which is prepared by optimizer.
Syntax: - EXPLAIN SELECT * FROM EMP WHERE COMM IS NOT NULL
Teradata Logical and Conditional Operators: -Logical Operators: -
AND, OR, BETWEEN AND are known as logical operators to defines the conditions in WHERE Clause.
The multiple conditions can be combined using logical operators.
AND Syntax: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE SAL > 2000 AND DEPTNO = 30
OR Syntax: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE SAL > 2000 OR DEPTNO = 30
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE (DEPTNO = 10 OR DEPTNO = 20) AND (SAL>2000)
BETWEEN AND Syntax: -
It returns the range of values between two given values
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE SAL BETWEEN 1500 AND 2500
Conditional Operators: -ISNULL: -
It verifies the NULLS on the given columns
Syntax: - SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE COMM IS NULL
IS NOT NULL Syntax: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE COMM IS NOT NULL
IN Operator: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE DEPTNO IN (10, 20)
IN NOT NULL: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE DEPTNO NOT IN (20, 30)
LIKE Operator: -
SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE ENAME LIKE S%Teradata SQL Extensions Date Arithmetics: -
The current date and time can be displayed with the following extensions
SELECT DATE
SELECT CURRENT_DATE
SELECT TIME
SELECT CURRENT_TIME
SELECT CURRENT_TIMESTAMP (displays both date & time)
Date Arithmetic: -Syntax: -
SELECT EMPNO, ENAME, SAL, JOB, DEPTNO, HIREDATE, (DATE_HIREDATE)/365 AS EXP FROM EMP
Date Extracts: -
Extract is a function
SELECT EXTRACT (YEAR FROM CURRENT_DATE)
SELECT EXTRACT (MONTH FROM CURRENT_DATE)
SELECT EXTRACT (MONTH FROM CURRENT_DATE+30)
SELECT EXTRACT (DAY FROM CURRENT_DATE)
SELECT EXTRACT (DAY FROM CURRENT_DATE+2)
SELECT EXTRACT (HOUR FROM CURRENT_TIME)
DATE Arithmetic in WHERE Clause: - Displays employees experience greater than 26 years
SELECT EMPNO, ENAME, SAL, JOB, DEPTNO, (DATE_HIREDATE)/365 AS EXPERIENCE FROM EMP WHERE (DATE_HIREDATE)/365 >= 26String Functions: -String Operator: -
Pipe is a concatenate operator which puts two string together
Syntax: - SELECT ENAME || , || ENAME AS EMPLOYEE FROM EMP WHERE DEPTNO=20
Sub String Function: -
It returns the part of the string from character string
Syntax: -
SELECT EMPNO, ENAME, SAL, DEPTNO FROM EMP WHERE SUBSTR (ENAME, 1, 1) = S
Note: -
We can use string literals in a sub string function to return the part of the string.
Syntaxes: -
SELECT SUBSTR (CATALOG, 5, 3)
SELECT SUBSTRING (CATALOG FROM 5 FOR 3)
Character Function: -
Count the number of characters in a string.
Syntax: -
SELECT EMPNO, ENAME, SAL, JOB, DEPTNO FROM EMP WHERE CHAR (ENAME) >= 5
TRIM Function: -
It removes the spaces (or) blanks from the both sides of the stringSyntax: -
SELECT EMPNO, ENAME, SAL, JOB, DEPTNO FROM EMP WHERE CHAR (TRIM (ENAME)) >= 6
Position Function: -
It locates a character position in a string
Syntax: - SELECT POSITION (M IN SMITH)
MACROS: -
Macro contains one (or) more prewritten SQL statements
Macros are a Teradata extension to ANSI SQL
Macros are stored in the Teradata data dictionary
Macros can be executed from any SQL front ends
I. SQL AssistantII. BTEQThe following are the Macro related commands
i) Create Macro: -
It creates a Macro and stores in the data dictionary
ii) Execute Macro Name: -
Executes the SQL statements within the Macro
iii) Show macro: -
It displays how the Macro was created
A Macro is created for frequently occurring queries (or) set of operations.
Macros are similar to Stored Procedures in oracle with no control flow statements [while loop, for loop etc].
All Macro statements are treated as a single transaction.
Re-optimized the execution time.
Accept users provided parameters.
Note: -In views the data definition can be update used a command called REPLACE.Syntax: -
REPLACE VIEW EMP_VIEW AS SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO=10;
Syntax to create a Macro: -
CREATE MACRO M_EMP20 AS (SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO=20 ;);
Macro Execution: -
A Macro is executed using EXECUTE command.
Syntax: - EXECUTE M_EMP
To display how a macro was created we use SHOW commandSyntax: - SHOW Macro M_EMP
Updating Macro definition: -
Use the REPLACE command to update an existing macro definition
Syntax: -
REPLACE MACRO M_EMP AS (SELECT EMPNO, ENAME, JOB, SAL, COMM, DEPTNO FROM EMP WHERE DEPTNO=10 ;);
Parameterized Macros: -
Parameterized macro allows substitute variables.
Values for these variables are supplied at runtime.
Macros may have more than one parameter.
Each name and it is associated data type are separated by comma from the next name and it is associated data type.
The order is important.
Creation of Parameterized Macro (Single Parameter)
i) Create Macro M_DEPT_LIST (DNO INTEGER) AS (SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE DEPTNO=: DNO ;);
Execution of Macro: - EXECUTE M_DEPT_LIST (20);
ii) Create Macro Sales.get_Customers (V-Nation varchar (30)) AS (SELECT C_CUSTKEY, C_NAME FROM Sales. CLIENT a, Sales. AREA b WHERE a.C_NATION KEY = b.N_NATION KEY and b.N_NAME =:V_NATION ;);EXEC Sales.get_Customers (INDIA)
Here Sales is our database where Macro gets stored.
iii) Create Parameterized Macro to insert a recordCREATE MACRO NEW_EMP ( ENO INTEGER,
NAME VARCHAR (10),
SAL DECIMAL (7, 2),
DNO INTEGER)
AS (INSERT INTO EMP (EMPNO, ENAME, SAL, DEPTNO) VALUES
(:ENO, :NAME, :SAL, :DEPTNO););
EXEC NEW_EMP (7666, SIVA, 4500, 10);
EXEC NEW_EMP (7666, , 4500, 10);
EXEC NEW_EMP (ENO=7666, NAME= SIVA, SAL= 4500, DNO= 10);
SELECT EMPNO, ENAME, SAL, DEPTO FROM EMP;
Sample Macro: -
CREATE MACRO NEW SALE (BOOKNUM SMALL INT, SDATE DATE, QTY SMALLINT)AS (SELECT :BOOKNUM (TITLE BOOK), :SDATE (TITLE DATE, FORMAT MMMBDDBYYYY), QTY (TITLE NBR SOLD) FROM BOOK_SALES_HISTROY;
INSERT INTO BOOK_SALES_HISTORY (BOOK_NUMBER, SALES_DATE, SALES_QUANTITY) VALUES (: BOOKNUM, :SDATE, :QTY););
EXEC NEWSALE (123, 20000130, 6);
EXEC NEWSALE (QTY=6, BOOKNUM=123, SDATE=20000130);
Note: -
You can create a Macro to preserve Integrity
Table level constraints are defined at last column in the table.
Column level constraint are defined at specifically create to a column.
To check multiple columns we use table level constraints.
Create a Macro to Preserve Integrity: -
CREATE TABLE EMP TEST (EMP_ID INTEGER NOT NULL, NAME VARCHAR (10), SAL DECIMAL (7, 2), DNO INTEGER, CONSTRAINT CHECK (SAL>1000 AND DNO BETWEEN 10 AND 40) ;);
SHOW TABLE EMP TEST;
CREATE A MACRO NEW_EMPLYEE (ENO INTEGER, NAME VARCHAR (10), SAL DECIMAL (7, 2), DNO INTEGER)
AS (ROLLBACK WORK INVALID SALARY WHERE :SAL40;
INSERT INTO EMP TEST (EMP_ID, NAME, SAL, DNO) VALUES (:ENO, :NAME, :SAL, :DNO) ;);
EXEC NEW_EMPLOYEE (7888, SIVA, 8000, 40)
BTEQ (Basic Teradata Query)
The BTEQ is a interactive and batch SQL utility.
It can be used for Import and Export of data.
It can be used as report writer.
Useful for error handling.
All BTEQ commands begin with the period (.).
SQL statements in the BTEQ scripts do not have begin period and have trialing semi colon.
Interactive Utility: -
Procedure1: -
Access the command prompt
Type BTEQ and press ENTER to invoke interactive environment
.LOGON 127.0.0.1/TDUSER (press ENTER)
** Logon successfully completed
Enter the following SQL request
SELECT EMPNO, ENAME, JOB, SAL, COMM, DEPTNO FROM Sales.EMP WHERE COMM IS NOT NULL (press ENTER)
To EXIT from Interactive environment
Type .QUIT (press ENTER)
Procedure2: -
To access BTEQ
Start ( Programs ( Teradata Client ( Teradata BTEQ
Select ASCII character set
Click on OK
Batch Utility: -
It can execute multiple SQL statements with the BTEQ scripts.
Note: - We can use SQL as a single statement request as well as multi statement request
EX: - BTEQ.txt
.LOGON 127.0.0.1/TDUSER, TDUSER;
Database Sales;
Create table BTEQ_CUST, NO FALLBACK, NO BEFORE JOURNAL,
NO AFTER JOURNAL (CUSTOMERID CHAR (5) NOT NULL,
COMPANY NAME VARCHAR (40) NOT NULL)
UNIQUE PRIMARY INDEX (CUSTOMERID);
INSERT BTEQ_CUST VALUES (C0001, HSBC);
INSERT BTEQ_CUST VALUES (C0002, ATT);
:QUIT;
Running the BTEQ Script: -
Open the command prompt
Type the following syntax to run the script
BTEQ T.AVGSAL
DROP TABLE MY_TEMP
DERIVED TABLES: -
A Derived table is a named temporary table obtained from sub query.
A Derived table allows you to directly access the derived results in other parts of overall SQL statements.
Derived tables allow the user benefits of Interim tables but within the syntax of single SQL statements.
Conceptually the approach is same of for four separate SQL statements it may be achieved in single SQL statements.
Derived tables are temporary tables that are created and dropped in part of query.
They permits the use of aggregates in WHERE clause
SELECT EMPNO, ENAME, SAL, AVGSAL FROM (SELECT AVG (SAL) FROM EMP) MY_TEMP (AVGSAL), EMP WHERE SAL>AVGSAL ORDER BY 3OUTPUT ATTRIBUTES: -
Output attributes defines and alias name for columns. The following are known as Output attributes AS, TITLE and NAMED.
AS: -
SELECT EMPNO, ENAME, JOB, SAL, SAL*0.15 AS TAX, DEPTNO FROM EMP ORDER BY TAX
NAMED: -
SELECT EMPNO, ENAME, JOB, SAL, SAL*0.15 (NAMED TAX), DEPTNO FROM EMP ORDER BY TAX
AS is an ANSI standard Output attribute
The following are the Teradata SQL extensions to define Output attributes
i) Title
ii) Named
SELECT EMPNO, ENAME, JOB, SAL, SAL*0.15 AS TAX, DEPTNO FROM EMP ORDER BY 5
SELECT EMPNO, ENAME, JOB, SAL, SAL*0.15 (TITLE TAX), DEPTNO FROM EMP ORDER BY 5
OLAP FUNCTIONS: -
RANK: -
a) Simple Ranking: -SELECT EMPNO, ENAME, JOB, SAL, DEPTNO, RANK () OVER (ORDER BY SAL DESC) AS RANKING FROM EMP QUALIFY RANKING