Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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