Syntax of Teradata SQL
Posted on Oct 15, 2014 in Computer Science
Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.
** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **
Syntax
-
Each Teradata SQL statement must be ended by a semicolon.
-
The keyword
inner
is optional in aninner join
. -
To estimate the time and space complexity, you can prefix your SQL code by
explain
, or you can just press theExplain
button if you use Teradata SQL Assistant. -
Column names in
select
andgroup by
,order by
, etc. are separated by comma. There can be no comma after the last column name. This is easy to understand. If you put comma after the last column in a, e.g.,select
clause, thefrom
keyword will be treated as the last column and results in syntax error.
Common Syntax Errors
-
Using a comma after the last column or missing a comma after a non-last column in the
select
clause. -
Miss
then
in acase
statement.case when condition_1 then v_1 when condition_2 then v_2 ... else v_k end
-
For
with data
orwith no data
when creating a table. CREATE TABLE Failed. 3706: Syntax error: expected something between ')' and ';'.
SQL Style
-
It is suggested that you write SQL code in the following style.
:::sql create table t0 as ( select distinct top 5 * from t1 inner join t2 on condition where condition group by 1 having condition order by 1 ) with data primary index (f1, f2)