mysql语法问题,错误1064 42000

时间:2014-05-23 16:26:07

标签: mysql

我收到此错误。我想知道我是否遗漏了一些明显的东西:

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 'Usage (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  powerType VARCHAR(100),
  usageD' at line 1

这是代码:

CREATE TABLE Users (
ID INT(10) NOT NULL AUTO_INCREMENT,


username VARCHAR(100),
  hashPass VARCHAR(100),
  firstName VARCHAR(100),
  lastName VARCHAR(100),
  address1 VARCHAR(100),
  address2 VARCHAR(100),
  city VARCHAR(100),
  state VARCHAR(100),
  zip INT(5),
  userRole VARCHAR(100),
  clientID INT(10),
  email VARCHAR(100),
  phone1 VARCHAR(100),
  phone2 VARCHAR(100),
   PRIMARY KEY(ID),
   FOREIGN KEY(clientID) REFERENCES Clients(ID)
);

CREATE TABLE Clients (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  companyName VARCHAR(100),
  address1 VARCHAR(100),
  address2 VARCHAR(100),
  city VARCHAR(100),
  state VARCHAR(100),
  zip INT(5),
  phone1 VARCHAR(100),
  phone2 VARCHAR(100),
  clientID INT,
  PRIMARY KEY  (ID)
);

CREATE TABLE ServiceAccounts (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  accountNumber VARCHAR(100),
  email VARCHAR(100),
  companyEmail VARCHAR(100),
  phone1 VARCHAR(100),
  phone2 VARCHAR(100),
  clientID INT(10),
  PRIMARY KEY (ID),
  FOREIGN KEY (clientID) REFERENCES Clients(ID)

);

CREATE TABLE Usage (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  powerType VARCHAR(100),
  usageDate DATE,
  startTime TIME,
  endTime TIME,
  usage DECIMAL(10,2),
  unitsType VARCHAR(100),
  cost DECIMAL(10, 2),
  accountNumber VARCHAR(100),
  serviceAccountID INT(10),
  PRIMARY KEY (ID),
  FOREIGN KEY (serviceAccountID) REFERENCES ServiceAccounts(ID)
);

CREATE TABLE Meters (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  meterID VARCHAR(100),
  serviceAccountID INT(10),
  address1 VARCHAR(100),
  address2 VARCHAR(100),
  city VARCHAR(100),
  state VARCHAR(100),
  zip INT(5),
  PRIMARY KEY (ID),
  FOREIGN KEY (serviceAccountID) REFERENCES ServiceAccounts(ID)
);

CREATE TABLE RateTiers (
  ID INT(10) NOT NULL AUTO_INCREMENT,
  TierID VARCHAR(100),
  rateTierID INT,
  PRIMARY KEY  (ID)
);

此外,我不知道这是否相关......但是Sublime2会突出显示VARCHARINT,但它不会突出显示TIMEDECIMAL。为什么它不将这些视为类型?

1 个答案:

答案 0 :(得分:1)

Usage是保留字:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

你必须用反引号来逃避它:

CREATE TABLE `Usage` ...
             ^-----^---