1
CREATE TABLE plan 
  ( 
     id                VARCHAR(30) NOT NULL, 
     name              VARCHAR(20), 
     amount            INT, 
     interval          INT, 
     currency          CHAR(3), 
     object            VARCHAR(20), 
     livemode          BOOLEAN, 
     interval_count    INT, 
     trial_period_days INT, 
     created           TIMESTAMP, 
     updated           TIMESTAMP, 
     deleted           TIMESTAMP, 
     PRIMARY KEY (id) 
  ); 

Produces

'ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval          INT, 
     currency          CHAR(3), 
     object            ' at line 6'

Doesn't work. However if the 'l' at the end of 'interval' is removed. It works.

CREATE TABLE plan 
  ( 
     id                VARCHAR(30) NOT NULL, 
     name              VARCHAR(20), 
     amount            INT, 
     interva           INT, 
     currency          CHAR(3), 
     object            VARCHAR(20), 
     livemode          BOOLEAN, 
     interval_count    INT, 
     trial_period_days INT, 
     created           TIMESTAMP, 
     updated           TIMESTAMP, 
     deleted           TIMESTAMP, 
     PRIMARY KEY (id) 
  ); 

I don't understand if this is a problem with attempting to use 'interval' and 'interval_count'. What's going on here.

1 Answer 1

3

The word "interval" is a reserved word. You can still use it if you quote it correctly.

See the MySQL Manual for a list of the reserved words and how to use them. In fact, "interval" is the first example in the link provided:

mysql> CREATE TABLE interval (begin INT, end INT);
ERROR 1064 (42000): You have an error in your SQL syntax ...
near 'interval (begin INT, end INT)'

mysql> CREATE TABLE `interval` (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.