-4
CREATE TABLE ec_recurring 
(   
    [recurring id] int NOT NULL IDENTITY,   
    [price] decimal(10,4) NOT NULL,
    [frequency] enum('day','week','semi_month','month','year') NOT NULL,   
    [duration] cast(10 as int) unsigned NOT NULL,
    [cycle] cast(10 as int) unsigned NOT NULL,
    [trial status] tinyint(4) NOT NULL,
    [trial price] decimal(10,4) NOT NULL,
    [trial frequency] enum('day','week','semi_month','month','year') NOT NULL,   
    [trial duration] cast(10 as int) unsigned NOT NULL,
    [trial cycle] cast(10 as int) unsigned NOT NULL,
    [status] tinyint(4) NOT NULL,   
    [sort order] cast(11 as int) NOT NULL,
    [date created] datetime2 NOT NULL,   
    [date modified] datetime2 NOT NULL,
    [created by] varchar(20) NOT NULL,   
    [modified by] varchar(20) NOT NULL,
    [active] tinyint(4) NOT NULL,   

    PRIMARY KEY ([recurring id])
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 

This was my code. Why does this error happen near day and cast?

Msg 102, Level 15, State 1, Line 3922
Incorrect syntax near 'day'

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vino Thini
  • 79
  • 9

2 Answers2

2

If we are talking about T-SQL, then the error near day means that the syntax is incorrect (simply there is no enum keyword in T-SQL), it should be something like this:

[frequency] VARCHAR(10) NOT NULL,
CONSTRAINT ck_Enum CHECK ([frequency] IN('day','week','semi_month','month','year')), 

Considering the second error you use cast in the wrong context, SQL doesn't know the type of the column. I believe that you wanted to write:

[duration] INT DEFAULT 10 NOT NULL 
CONSTRAINT ck_Duration CHECK ([duration] > 0), 

With additional checking whether duration is unsigned. You should obey the language's syntax because you have some more errors. Let the following be an example for you:

CREATE TABLE ec_recurring 
( 
[recurring id]      INT IDENTITY NOT NULL
CONSTRAINT pl_recId PRIMARY KEY, 

[price]             DECIMAL(10, 4) NOT NULL,

[frequency]         VARCHAR(10) NOT NULL,
CONSTRAINT ck_Enum CHECK ([frequency] IN('day','week','semi_month','month','year')), 

[duration]          INT DEFAULT 10 NOT NULL 
CONSTRAINT ck_Duration CHECK ([duration] > 0), 

[cycle]             INT DEFAULT 10 NOT NULL 
CONSTRAINT ck_Cycle CHECK ([cycle] > 0), 

[trial status]      TINYINT DEFAULT 4 NOT NULL, 

[trial price]       DECIMAL(10, 4) NOT NULL, 

[trial frequency]   VARCHAR(10) NOT NULL 
CONSTRAINT ck_TrialEnum CHECK ([trial frequency] IN('day','week','semi_month','month','year')), 

[trial duration]    INT DEFAULT 10 NOT NULL 
CONSTRAINT ck_TrialDuration CHECK ([trial duration] > 0), 

[trial cycle]       INT DEFAULT 10 NOT NULL 
CONSTRAINT ck_TrialCycle CHECK ([trial cycle] > 0), 

[status]            TINYINT DEFAULT 4 NOT NULL, 

[sort order]        INT DEFAULT 11 NOT NULL, 

[date created]      DATETIME2 NOT NULL, 

[date modified]     DATETIME2 NOT NULL, 

[created by]        DATETIME NOT NULL, 

[modified by]       DATETIME NOT NULL, 

[active]            TINYINT DEFAULT 4 NOT NULL, 
);
Izi
  • 59
  • 3
  • 12
1

In Microsoft's SQL Server is no such thing as enum, it is from MySql, but you can use its equivalent:

mycol VARCHAR(10) NOT NULL CHECK (mycol IN('Useful', 'Useless', 'Unknown'))

Original Post

SᴇM
  • 7,024
  • 3
  • 24
  • 41