MySQL Workbench错误1064错误

时间:2016-04-10 14:54:57

标签: mysql mysql-workbench

我知道这个问题已被多次询问过。我正在完成我的任务,即为汽车保险公司创建一个数据库。遇到语法问题。

尝试运行我的代码后,出现错误:

read user_data
echo $user_data >> user_string

我的表格如下:

    Executing SQL script in server
ERROR: Error 1064: 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 'Primary key,
  `Address` VARCHAR(100) NOT NULL DEFAULT 'Persons Address',
  `Add' at line 5
SQL Code:
        -- -----------------------------------------------------
        -- Table `insurance`.`DriverAddress`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `insurance`.`DriverAddress` (
          `Address_ID` MEDIUMTEXT NOT NULL DEFAULT Primary key,
          `Address` VARCHAR(100) NOT NULL DEFAULT 'Persons Address',
          `Address2` VARCHAR(100) NOT NULL DEFAULT 'Additional line',
          `City` VARCHAR(100) NOT NULL DEFAULT 'City',
          `County` VARCHAR(50) NOT NULL DEFAULT 'County',
          `SortCode` VARCHAR(20) NOT NULL DEFAULT 'Sort Code',
          `Country` VARCHAR(100) NOT NULL DEFAULT 'Country',
          PRIMARY KEY (`Address_ID`))
        ENGINE = InnoDB

SQL script execution finished: statements: 5 succeeded, 1 failed

Fetching back view definitions in final form.
Nothing to fetch

如果有人能指导我朝着正确的方向前进,我将非常感激。

1 个答案:

答案 0 :(得分:1)

你有DEFAULT主键..尝试在第一行没有默认值,例如:AUTO_INCREMENT或没有

CREATE TABLE IF NOT EXISTS `insurance`.`DriverAddress` (
      `Address_ID` MEDIUMTEXT NOT NULL AUTO_INCREMENT,
      `Address` VARCHAR(100) NOT NULL DEFAULT 'Persons Address',
      `Address2` VARCHAR(100) NOT NULL DEFAULT 'Additional line',
      `City` VARCHAR(100) NOT NULL DEFAULT 'City',
      `County` VARCHAR(50) NOT NULL DEFAULT 'County',
      `SortCode` VARCHAR(20) NOT NULL DEFAULT 'Sort Code',
      `Country` VARCHAR(100) NOT NULL DEFAULT 'Country',
      PRIMARY KEY (`Address_ID`))
    ENGINE = InnoDB