I’m using Teradata SQL assistant to create a table. The code I am using is as follows:
CREATE TABLE calendar ( CalendarKey INT NOT NULL, FullDate DATE NOT NULL, DayOfWeek VARCHAR(20) NOT NULL, DayOfMonth INT NOT NULL, Month VARCHAR(20) NOT NULL, Qtr VARCHAR(2) NOT NULL, Year VARCHAR(4) NOT NULL PRIMARY KEY (CalendarKey) );
I get this error when I try to execute the command:
[Teradata Database] [3707] Syntax error, expected something like a ‘CHECK’ keyword between ‘,’ and the ‘Month’ keyword.
Does anyone know what the issue is?
Advertisement
Answer
As the error implies month
(and year
, too) is a reserved keyword in Teradata, which can’t be used as column name.
You might double quote it (but then you have to double quote it in every query, too) or you change the name. There’s another issue, a missing comma before the primary key
constraint:
CREATE TABLE calendar ( CalendarKey INT NOT NULL, FullDate DATE NOT NULL, DayOfWeek VARCHAR(20) NOT NULL, DayOfMonth INT NOT NULL, "Month" VARCHAR(20) NOT NULL, Qtr VARCHAR(2) NOT NULL, "Year" VARCHAR(4) NOT NULL, PRIMARY KEY (CalendarKey) );