0% found this document useful (0 votes)
38 views

Teradata SQL Cheat Sheet _ Free Download – ETL with SQL

Uploaded by

Anupam Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Teradata SQL Cheat Sheet _ Free Download – ETL with SQL

Uploaded by

Anupam Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

Teradata SQL Cheat Sheet | Free


Download
I am sharing below some Teradata SQL queries which can quickly help
you brush your SQL. I have tried to cover all the common SQL operations
in Teradata and will keep on adding more. Hope this helps.

Teradata SQL Cheat Sheet

1. [DDL] CREATE / ALTER / DROP / RENAME TABLE : 19


Queries
2. SELECT : 38 Queries
3. Metadata/System Tables & Views : 11 Queries

https://etl-sql.com/teradata-sql-cheat-sheet/ 1/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

4. [DML] INSERT / UPDATE / DELETE / MERGE : 12 Queries

FREE Download (pdf)

[DDL] CREATE / ALTER / DROP / RENAME


TABLE

1 CREATE table with column list


SQL
create table test_datatype(
col1 byteint,
col2 smallint,
col3 integer,
col4 bigint,
col5 char(10),
col6 varchar(10),
col7 date,
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
);

2 CREATE table with column list with PRIMARY INDEX


SQL
create table test_datatype2(
col1 byteint,
col2 smallint,
col3 integer,
col4 bigint,
col5 char(10),
col6 varchar(10),
col7 date,

https://etl-sql.com/teradata-sql-cheat-sheet/ 2/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) primary index(col2);

3 CREATE table with column list with NO PRIMARY


INDEX
SQL

create table test_datatype3(


col1 byteint,
col2 smallint,
col3 integer,
col4 bigint,
col5 char(10),
col6 varchar(10),
col7 date,
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) NO primary index;

4 CREATE table from other table with no-data


SQL

create table test_ctas1 as test_datatype with no data;

5 CREATE table from other table with no-data but


different PRIMARY INDEX
SQL

create table test_ctas2 as test_datatype with no data primary


index (col2);

https://etl-sql.com/teradata-sql-cheat-sheet/ 3/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

6 CREATE table from other table with data


SQL
create table test_ctas3 as test_datatype with data;

7 CREATE table from other table with data but different


PRIMARY INDEX
SQL
create table test_ctas4 as test_datatype with data primary
index (col2);

8 CREATE table from SELECT with no data


SQL
create table test_ctas5 as (
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
WHERE
w_state = 'KS'
) with no data;

9 CREATE table from SELECT with no data but different


PRIMARY INDEX
SQL
create table test_ctas6 as
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city

https://etl-sql.com/teradata-sql-cheat-sheet/ 4/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

FROM
WAREHOUSE
WHERE
w_state = 'KS' with no data primary index (w_warehouse_id);

10 CREATE table from SELECT with data


SQL
create table test_ctas7 as (
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
WHERE
w_state = 'KS'
) with data;

11 CREATE table from SELECT with data but different


PRIMARY INDEX
SQL
create table test_ctas8 as (
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
WHERE
w_state = 'KS'
) with data primary index (w_warehouse_id);

12 CREATE table from SELECT with no data by adding


filter condition

https://etl-sql.com/teradata-sql-cheat-sheet/ 5/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SQL

create table test_ctas9 as (


SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
WHERE
1 = 0
) with no data;

13 CREATE VOLATILE table


SQL

create VOLATILE table vt_datatype(


col1 byteint,
col2 smallint,
col3 integer,
col4 bigint,
col5 char(10),
col6 varchar(10),
col7 date,
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) primary index(col2) ON COMMIT PRESERVE ROWS;

14 CREATE GLOBAL TEMPORARY table


SQL

create GLOBAL TEMPORARY table gt_datatype(


col1 byteint,
col2 smallint,
col3 integer,
col4 bigint,
https://etl-sql.com/teradata-sql-cheat-sheet/ 6/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

col5 char(10),
col6 varchar(10),
col7 date,
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) primary index(col2);

15 ADD new column in the table


SQL

ALTER table
warehouse
ADD
w_warehouse_new varchar(30),
ADD
w_warehouse_new2 varchar(30);

16 DROP existing column from the table


SQL

ALTER table
warehouse
DROP
w_warehouse_new,
DROP
w_warehouse_new2;

17 RENAME existing column to new name


SQL

ALTER table
warehouse RENAME w_warehouse_name to w_wh_nm;

https://etl-sql.com/teradata-sql-cheat-sheet/ 7/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

18 RENAME table to new name


SQL
RENAME TABLE warehouse to warehouse_new;

19 DROP table from database


SQL
DROP
TABLE warehouse;

SELECT

20 SELECT all columns and all rows from table


SQL
SELECT
*
from
WAREHOUSE;

21 SELECT few columns and all rows from table


SQL
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE;

22 SELECT all columns and few rows from table


SQL

SELECT
*
https://etl-sql.com/teradata-sql-cheat-sheet/ 8/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

from
WAREHOUSE sample 10;

23 SELECT all columns and few rows from table –


another approach
SQL
SELECT
Top 10 *
from
WAREHOUSE;

24 SELECT all columns and FILTER rows from table


SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state = 'KS';

25 SELECT all columns and FILTER rows , multiple


conditions (AND) from table
SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state = 'TN'
and w_city = 'Fairview';

26 SELECT all columns and FILTER rows , multiple


conditions (OR) from table
https://etl-sql.com/teradata-sql-cheat-sheet/ 9/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state = 'TN'
OR w_state = 'VA';

27 SELECT all columns and FILTER rows , multiple


conditions (OR) on same column using IN
SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state IN ('TN', 'VA');

28 SELECT DISTINCT rows from table


SQL
SELECT
DISTINCT *
from
WAREHOUSE;

29 SELECT DISTINCT column rows from table


SQL
SELECT
DISTINCT w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE;
https://etl-sql.com/teradata-sql-cheat-sheet/ 10/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

30 SORT output rows


SQL
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
ORDER BY
w_warehouse_id asc,
w_city desc;

31 SORT output rows by column position


SQL
SELECT
w_warehouse_sk,
w_warehouse_id,
w_city
FROM
WAREHOUSE
ORDER BY
2 asc,
3 desc;

32 NULL check for column value


SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state IS NOT NULL
and w_city is NULL;

https://etl-sql.com/teradata-sql-cheat-sheet/ 11/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

33 Fetch MAX, MIN, COUNT, AVG,SUM for measures in


table
SQL
SELECT
MAX(w_warehouse_sq_ft),
MIN(w_warehouse_sq_ft),
COUNT(w_warehouse_sq_ft),
AVG(w_warehouse_sq_ft),
SUM(w_warehouse_sq_ft)
FROM
WAREHOUSE;

34 Check total records in the table


SQL
SELECT
COUNT(*)
FROM
WAREHOUSE;

35 Check total distinct records in the table


SQL
SELECT
COUNT(*)
FROM
(
select
distinct *
from
WAREHOUSE
) tb1;

36 Check for string pattern in column values


https://etl-sql.com/teradata-sql-cheat-sheet/ 12/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state like 'T % ';

37 Check for multiple string pattern in column values


SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state like any ('T % ', 'V % ');

38 Check for rows BETWEEN range values


SQL
select
*
from
date_dim
where
d_date between '2019 - 01 - 01'
and '2019 - 01 - 31';

39 Create ALIAS name for columns


SQL
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
w_city as w_city
FROM
https://etl-sql.com/teradata-sql-cheat-sheet/ 13/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

WAREHOUSE;

40 Create ALIAS name for tables


SQL

SELECT
tb1.w_warehouse_sk,
tb1.w_warehouse_id,
tb1.w_city
FROM
WAREHOUSE tb1;

41 Use COALESCE to set value when NULL exists


SQL

SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
COALESCE(w_city, 'Not Available') as w_city
FROM
WAREHOUSE;

42 Use CASE to create new derived table


SQL
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
w_city as w_city,
CASE when w_state = 'California' then 'CA' when w_state =
'Florida' then 'FL' when w_state = 'Michigan' then 'MI' when
w_state = 'New Jersey' then 'NJ' when w_state = 'New York'
then 'NY' when w_state = 'Texas' then 'TX' when w_state =
'Virginia' then 'VA' else 'Other States' END as w_state_abbr
FROM
WAREHOUSE;

https://etl-sql.com/teradata-sql-cheat-sheet/ 14/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

43 INNER JOIN
SQL

select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
INNER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';

44 LEFT OUTER JOIN


SQL
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
LEFT OUTER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';

45 RIGHT OUTER JOIN

https://etl-sql.com/teradata-sql-cheat-sheet/ 15/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SQL

select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
RIGHT OUTER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';

46 FULL OUTER JOIN


SQL

select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1 FULL
OUTER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';

47 SELF JOIN
SQL
select
tb1.w_warehouse_sk,
tb1.w_warehouse_name
https://etl-sql.com/teradata-sql-cheat-sheet/ 16/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

from
warehouse tb1,
warehouse tb2
where
tb1.w_warehouse_id = tb2.w_warehouse_id
and tb1.w_state = tb2.w_state
and tb1.w_warehouse_sk = 1;

48 LEFT OUTER JOIN to find rows which does not exists


in LEFT table
SQL

select
tb1.w_warehouse_name,
_tb1.w_state,
tb1.w_city
from
warehouse tb1
left outer join inventory tb2 on tb1.w_warehouse_sk =
tb2.inv_warehouse_sk
where
tb2.inv_warehouse_sk is null;

49 LEFT OUTER JOIN to find rows which does exists in


LEFT table (same as INNER JOIN)
SQL
select
tb1.w_warehouse_name,
_tb1.w_state,
tb1.w_city
from
warehouse tb1
left outer join inventory tb2 on tb1.w_warehouse_sk =
tb2.inv_warehouse_sk
where
tb2.inv_warehouse_sk is not null;

https://etl-sql.com/teradata-sql-cheat-sheet/ 17/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

50 ROW NUMBER olap function


SQL

select
w_warehouse_name,
w_state,
w_city,
row_number() over(
partition by w_zip
order by
w_warehouse_sq_ft desc
) as w_warehouse_no
from
warehouse;

51 RANK olap function


SQL
select
w_warehouse_name,
w_state,
w_city,
rank() over(
partition by w_zip
order by
w_warehouse_sq_ft desc
) as w_warehouse_no
from
warehouse;

52 UNION set operator


SQL
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,

https://etl-sql.com/teradata-sql-cheat-sheet/ 18/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

w_city as w_city
FROM
WAREHOUSE
where
w_state = 'Virginia'
UNION
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
w_city as w_city
FROM
WAREHOUSE
where
w_state = 'Texas';

53 SELECT today's date


SQL

SELECT
CURRENT_DATE;

54 Add 5 days to date


SQL
SELECT
CURRENT_DATE + INTERVAL '5' DAY;

55 Add 5 months to date


SQL
SELECT
CURRENT_DATE + INTERVAL '5' MONTH;

56 Add 5 years to date


SQL

https://etl-sql.com/teradata-sql-cheat-sheet/ 19/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SELECT
CURRENT_DATE + INTERVAL '5' YEAR;

57 Subtract 2 dates
SQL

SELECT
cast('2019 - 12 - 31' as date) – cast('2019 - 04 - 01' as
date);

Metadata/System Tables & Views

58 Check for tablename in any database


SQL

select
*
from
dbc.tablesV
where
tablename = 'warehouse';

59 Check for tablename in specific database


SQL
select
*
from
dbc.tablesV
where
tablename = 'warehouse'
and databasename = 'tpcds';

60 Check for all tables in specific database


SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 20/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

select
*
from
dbc.tablesV
where
databasename = 'tpcds'
and tablekind in ('T', 'O');

61 Check for all objects in specific database


SQL

HELP database tpcds;

62 Check table structure


SQL

SHOW table warehouse;

63 Check for columns in any table


SQL
HELP table warehouse;

64 Check for columns in any table


SQL
select
*
from
dbc.columnsV
where
databasename = 'tpcds'
and tablename = 'warehouse'
order by
columnid;

https://etl-sql.com/teradata-sql-cheat-sheet/ 21/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

65 Check for tablesize in Teradata


SQL

select
databasename,
tablename,
sum(currentperm) as total_size_bytes
from
dbc.tablesize
where
tablename = 'warehouse'
and databasename = 'tpcds'
group by
databasename,
tablename;

66 Check for all VIEWS in specific database


SQL
select
*
from
dbc.tablesV
where
databasename = 'tpcds'
and tablekind = 'V';

67 Check for performance metrics of session


SQL
select
*
from
dbc.dbqlogtbl
where
sessionid = (

https://etl-sql.com/teradata-sql-cheat-sheet/ 22/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

select
session
);

68 Explain plan for the Query


SQL

EXPLAIN
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
INNER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';

[ DML ] INSERT / UPDATE / DELETE / MERGE

69 INSERT static records into table


SQL

INSERT into employee(


Name, City, County, State, Zip, Country
)
values
(
'Mark', 'Paris', 'NA',
'NA', 75000, 'France'
);

70 INSERT records into table from another table


https://etl-sql.com/teradata-sql-cheat-sheet/ 23/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

SQL
INSERT into employee(
Name, City, County, State, Zip, Country
)
SELECT
Name,
City,
County,
State,
Zip,
Country
from
stg_employee
where
zip = 75000
and country = 'France';

71 UPDATE table records from static values


SQL
UPDATE
employee
set
Country = 'France',
City = 'Paris';

72 UPDATE table records from static values with some


condition
SQL
UPDATE
employee
set
Country = 'France',
City = 'Paris'
where
zip = 75000;

https://etl-sql.com/teradata-sql-cheat-sheet/ 24/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

73 UPDATE table records from another table


SQL
UPDATE
tb1
from
employee tb1,
dim_add tb2
set
Country = tb2.Country,
City = tb2.City
where
tb1.zip = tb2.zip;

74 UPDATE table records from another derived table


SQL
UPDATE
tb1
from
employee tb1,
(
select
country,
city,
zip
from
dim_add
where
zip between 75000
and 75020
) tb2
set
Country = tb2.Country,
City = tb2.City
where
tb1.zip = tb2.zip;

https://etl-sql.com/teradata-sql-cheat-sheet/ 25/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

75 UPSERT table records


SQL
UPDATE
employee
set
Country = 'France',
City = 'Paris'
where
zip = 75000 ELSE INSERT into employee(
Name, City, County, State, Zip, Country
)
values
(
'Mark', 'Paris', 'NA',
'NA', 75000, 'France'
);

76 MERGE table records from Source table


SQL
MERGE into employee tb1 using stg_employee tb2 on tb1.zip =
tb2.zip WHEN MATCHED THEN
UPDATE
SET
Country = tb2.Country,
City = tb2.City WHEN NOT MATCHED THEN INSERT
VALUES
(
tb2.Name, tb2.City, tb2.County, tb2.State,
tb2.Zip, tb2.Country
);

77 DELETE entire table


SQL

https://etl-sql.com/teradata-sql-cheat-sheet/ 26/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

DELETE from
employee;

78 DELETE few records from table


SQL
DELETE from
employee
where
zip = 75000;

79 DELETE few records from table by looking into


another table
SQL
DELETE FROM
employee
where
zip NOT IN (
select
zip
from
stg_employee
);

80 DELETE few records from table by looking into


another table
SQL
DELETE FROM
employee
where
zip = stg_employee.zip;

If you want me to add few more SQL scenarios, feel free to leave
comments and I will include those SQL scenarios too.
https://etl-sql.com/teradata-sql-cheat-sheet/ 27/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

9 thoughts on “Teradata SQL Cheat Sheet | Free Download”

John says:
MARCH 14, 2023 AT 12:09 AM

Hi, Thank you for this. I have made ANKI flashcards from these would you mind
if I shared them?

Reply

Osic says:
MARCH 31, 2022 AT 2:39 AM

I guess, but I am not sure, there is a typo like below:


———————————————————–
75 UPSERT table records -> 75 UPDATE table records
———————————————————–

Reply

Aniket says:
OCTOBER 1, 2021 AT 12:28 PM

Thank you so much for sharing this wonderful content. I am fresher and have
just transitioned from Campus to Corporate life and have been given Data
Integration domain where I will be required to work on Teradata SQL Assistant
and Informatica Powercenter. Please share more of your experiences with us, it
would be very helpful.

Reply

Prerana says:
JUNE 3, 2021 AT 3:56 PM

https://etl-sql.com/teradata-sql-cheat-sheet/ 28/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

This was very helpful. Please make more of this sort.

Reply
Abhishek says:
MAY 23, 2021 AT 8:39 PM

The best place to visit again and again.


This will help most of freshers to learn and impress people around them.
I am happy to see such pages exist on web.

Reply

Raj says:
MAY 24, 2021 AT 9:31 AM

Thank you Abhishek for the appreciation.


Happy to help.

Reply

Sonia says:
DECEMBER 12, 2019 AT 3:45 AM

I need the years 2019 and 2020 to look like '2019-20' in a integer field which I
cannot change the data type. Someone suggested using trim and substring.
Can you please help me. Thanks

Reply

TestUser says:
JUNE 16, 2020 AT 2:21 PM

Use left cast and right cast for two dates and concatenate two dates into
one.
E.g. select concat(left(cast('2019-6-16' as varchar(23)), 5),right(cast('8-17-
2020' as varchar(25)), 2));

Reply
https://etl-sql.com/teradata-sql-cheat-sheet/ 29/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

Bhargav says:
SEPTEMBER 24, 2019 AT 6:44 PM

need interview based teradata sql queries and all utilities with an example,.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email * Website

Save my name, email, and website in this browser for the next time I
comment.

Notify me of new posts by email.

https://etl-sql.com/teradata-sql-cheat-sheet/ 30/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL

Post Comment

Categories Contact All Courses Social

Data Warehouse You can submit form Master SQL


General on contact page Interview Questions
Redshift Master SQL Query
SQL Optimisation
Teradata Amazon Redshift –
Zero to Hero
Teradata – Zero to
Hero

You can submit form


on courses page

© 2023 ETL with SQL.

https://etl-sql.com/teradata-sql-cheat-sheet/ 31/31

You might also like