这个MySQL语法有什么问题 - 错误1064 ..?

时间:2015-05-25 02:14:39

标签: mysql sql database

我正在尝试建立一个大学数据库,我遇到了一个问题。 当我执行文件(cmd中的源文件名)时出现此错误:

    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 'CREAT
E TABLE IF NOT EXISTS `Owner1` (
  `password1` varchar(100) NOT NULL defaul' at line 14

我似乎无法弄清楚SQL出错的地方(我多年来没有做过SQL)。

这是我的SQL:

--
-- Database : `db`
--
CREATE DATABASE IF NOT EXISTS `db`
  DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
USE db;

CREATE TABLE IF NOT EXISTS `Category` (
  `category_id` int(20) NOT NULL default '',
  `name` varchar(100) NOT NULL,
  `description` varchar(200) NOT NULL,
  `sub_category_id` int(20) NULL,

  PRIMARY KEY  (category_id, name),

  FOREIGN KEY Category(sub_category_id) REFERENCES Category(category_id) ON DELETE CASCADE
)   

-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Owner` (
  `password` varchar(100) NOT NULL default '',
  `account_name` varchar(100) NOT NULL default '',

  PRIMARY KEY  (password, account_name)

)   

CREATE TABLE IF NOT EXISTS `Company` (
  `name` varchar(100) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',
  `company_type` varchar(13) NOT NULL default '',
  `office_location` varchar(200) NOT NULL default '',
  `description` varchar(255) NOT NULL default '',
  `trade_mark` varchar(100) NOT NULL default '',
  `ph_num` varchar(12) NOT NULL default '',
  PRIMARY KEY  (name, password),

  FOREIGN KEY Company(name) REFERENCES Owner(account_name) ON DELETE CASCADE,
  FOREIGN KEY Company(password) REFERENCES Owner(password) ON DELETE CASCADE
)   

-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Individual` (
  `name` varchar(100) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',
  `contact` varchar(200) NOT NULL default '',
  `reg_exp` DATE NOT NULL,
  PRIMARY KEY  (name, password),

  FOREIGN KEY Invidual(name) REFERENCES Owner(account_name) ON DELETE CASCADE,
  FOREIGN KEY Invidual(password) REFERENCES Owner(password) ON DELETE CASCADE
)   

-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Product` (
  `EPC` varchar(200) NOT NULL default '',
  `expiry_date` DATE NOT NULL,
  `production_date` DATE NOT NULL,
  `prod_description` varchar(200) NOT NULL default '',
  `item_name` varchar(100) NOT NULL default '',
  `manufacturer_info` varchar(200) NOT NULL default '',
  `account_name` varchar(100) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',


  PRIMARY KEY  (EPC),

  FOREIGN KEY Product(account_name) REFERENCES Owner(account_name) ON DELETE CASCADE,
  FOREIGN KEY Product(password) REFERENCES Owner(password) ON DELETE CASCADE
)   
-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Prod_Cat` (
  `name` varchar(100) NOT NULL default '',
  `category_id` int(20) NOT NULL,
  `EPC` varchar(200) NOT NULL default '',
  PRIMARY KEY  (name, category_id, EPC),

  FOREIGN KEY Prod_Cat(name) REFERENCES Category(name) ON DELETE CASCADE,
  FOREIGN KEY Prod_Cat(EPC) REFERENCES Product(EPC) ON DELETE CASCADE,
  FOREIGN KEY Prod_Cat(category_id) REFERENCES Category(category_id) ON DELETE CASCADE
)   





-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `RFID_Reader` (
  `ip` varchar(50) NOT NULL default '',
  `type` varchar(7) NOT NULL,
  `account_name` varchar(100) NOT NULL default '',
  `password` varchar(100) NOT NULL default '',

  PRIMARY KEY  (ip),

  FOREIGN KEY (RFID_Reader.account_name) REFERENCES (Owner.account_name) ON DELETE CASCADE,
  FOREIGN KEY (RFID_Reader.password) REFERENCES (Owner.password) ON DELETE CASCADE
)   

-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Location` (
  `ip` varchar(50) NOT NULL default '',
  `longitude` varchar(7) NOT NULL,
  `lattitude` varchar(7) NOT NULL default '',
  `description` varchar(200) NOT NULL default '',

  PRIMARY KEY  (ip, longitude, lattitude),

  FOREIGN KEY Location(ip) REFERENCES RFID_Reader(ip) ON DELETE CASCADE
)   

-- --------------------------------------------------------

--- Here TODO

CREATE TABLE IF NOT EXISTS `Track_Record` (
  `location` varchar(50) NOT NULL default '',
  `product_type` varchar(100) NOT NULL,
  `date` DATE NOT NULL,
  `EPC` varchar(200) NOT NULL default '',
  `ip` varchar(50) NOT NULL default '',

  PRIMARY KEY  (ip, longitude, lattitude),

  FOREIGN KEY Location(ip) REFERENCES RFID_Reader(ip) ON DELETE CASCADE
)   

如果有人不介意指出我做错了什么,我会非常感激。

谢谢堆 科里:)

1 个答案:

答案 0 :(得分:1)

我认为在每个childWindow.document.getElementById('some_input_id').focus(); 语句之后,您需要在下一个CREATE TABLE ... ( ... )语句之前;。所以:

CREATE TABLE

会变成:

CREATE TABLE IF NOT EXISTS `Category` (
  `category_id` int(20) NOT NULL default '',
  `name` varchar(100) NOT NULL,
  `description` varchar(200) NOT NULL,
  `sub_category_id` int(20) NULL,

  PRIMARY KEY  (category_id, name),

  FOREIGN KEY Category(sub_category_id) REFERENCES Category(category_id) ON DELETE CASCADE
)   

-- --------------------------------------------------------

CREATE TABLE IF NOT EXISTS `Owner` (
  `password` varchar(100) NOT NULL default '',
  `account_name` varchar(100) NOT NULL default '',

  PRIMARY KEY  (password, account_name)

)   

等等。