SQL初学者错误创建表

时间:2014-04-26 12:08:27

标签: mysql sql database

所以我是sql的新手,我试图创建一系列的表不能似乎让它工作。我得到的错误消息是。 这些表都单独添加没有问题但是当我想立即导入所有这些时它给了我这个错误。

架构创建失败:您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在[客户]附近使用正确的语法(       CustomerID int PRIMARY KEY,       CustomerName varchar('在第1行:

CREATE TABLE IF NOT EXISTS  [Customer](
      CustomerID     int  PRIMARY KEY,
      CustomerName   varchar(50)  NOT NULL,
      BillingAddress varchar(400)  default NULL,
      PhoneNumber    int  default NULL,
      User_Email     varchar(128) UNIQUE
 )ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS [Order](
      OrderID             int NOT NULL  PRIMARY KEY,
      CustomerID          int,
      OrderDate           date  NOT NULL,
      PurchaseOrderNumber int
 )ENGINE=InnoDB DEFAULT CHARSET=latin1;





CREATE TABLE IF NOT EXISTS [OrderItem](
      OrderItemID    int  PRIMARY KEY,
      ProductID      int NOT NULL,
      OrderID        int NOT NULL,
      Quantity       int NOT NULL,
      PricePerUnit   double NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=latin1;




CREATE TABLE IF NOT EXISTS [Product](
       ProductID            int PRIMARY KEY,
       ProductName          varchar(100)  NOT NULL,
       ProductDescription   varchar(100)  NOT NULL,
       SerialNumber         int NOT NULL,
       UnitesInStock        int  NOT NULL,
       UnitsOnOrder         int NOT NULL,
       UnitPrice            double NOT NULL
       SupplierID           int not NULL
)ENGINE=InnoDB DEFAULT CHARSET=latin1;




CREATE TABLE IF NOT EXISTS [SupplySchedule](
       ShippingID        int PRIMARY KEY,
       ShippingMode      varchar(50) NOT NULL

)ENGINE=InnoDB DEFAULT CHARSET=latin1;







CREATE TABLE IF NOT EXISTS [Supplier](
        SupplierID       int PRIMARY KEY,
        SupplierName     varchar(40) NOT NULL,
        SupplierAddress  varchar(128) NOT NULL,
        ContactName      varchar(128) NOT NULL


   )ENGINE=InnoDB DEFAULT CHARSET=latin1;

2 个答案:

答案 0 :(得分:2)

order是MySQL中的reserved word。要么使用反引号来逃避它,要么使用其他名称。

CREATE TABLE IF NOT EXISTS `Order` (...

答案 1 :(得分:-1)

我已将Order表重命名为OrderMaster为" Order"是mysql保留字 尝试以下脚本:

drop table if exists Customer;
CREATE TABLE   Customer(
      CustomerID     int  PRIMARY KEY,
      CustomerName   varchar(50)  NOT NULL,
      BillingAddress varchar(400)  default NULL,
      PhoneNumber    int  default NULL,
      User_Email     varchar(128) UNIQUE
 )ENGINE=InnoDB DEFAULT CHARSET=latin1;

drop table if exists OrderMaster;
CREATE TABLE IF NOT EXISTS OrderMaster(
      OrderID             int NOT NULL  PRIMARY KEY,
      CustomerID          int,
      OrderDate           date  NOT NULL,
      PurchaseOrderNumber int
 )ENGINE=InnoDB DEFAULT CHARSET=latin1;




drop table if exists OrderItem;
CREATE TABLE OrderItem(
      OrderItemID    int  PRIMARY KEY,
      ProductID      int NOT NULL,
      OrderID        int NOT NULL,
      Quantity       int NOT NULL,
      PricePerUnit   double NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=latin1;



drop table if exists Product;
CREATE TABLE IF NOT EXISTS Product(
       ProductID            int PRIMARY KEY,
       ProductName          varchar(100)  NOT NULL,
       ProductDescription   varchar(100)  NOT NULL,
       SerialNumber         int NOT NULL,
       UnitesInStock        int  NOT NULL,
       UnitsOnOrder         int NOT NULL,
       UnitPrice            double NOT NULL,
       SupplierID           int not NULL
)ENGINE=InnoDB DEFAULT CHARSET=latin1;



drop table if exists SupplySchedule;
CREATE TABLE IF NOT EXISTS SupplySchedule(
       ShippingID        int PRIMARY KEY,
       ShippingMode      varchar(50) NOT NULL

)ENGINE=InnoDB DEFAULT CHARSET=latin1;






drop table if exists Supplier;
CREATE TABLE IF NOT EXISTS Supplier(
        SupplierID       int PRIMARY KEY,
        SupplierName     varchar(40) NOT NULL,
        SupplierAddress  varchar(128) NOT NULL,
        ContactName      varchar(128) NOT NULL


   )ENGINE=InnoDB DEFAULT CHARSET=latin1;