2016-04-10 1 views
0

Ich bin mir bewusst, dass diese Frage mehrmals gestellt wurde. Ich arbeite an meiner Aufgabe, eine Datenbank für eine Autoversicherung zu erstellen. Es ist ein Syntaxproblem aufgetreten.MySQL Workbench Fehler 1064 Fehler

Nach dem Versuch, meinen Code ich einen Fehler zu laufen:

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 

wie Meine Tabellennachschlagevorgang:

-- MySQL Workbench Forward Engineering 

SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 
SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 
SET @[email protected]@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; 

-- ----------------------------------------------------- 
-- Schema insurance 
-- ----------------------------------------------------- 

-- ----------------------------------------------------- 
-- Schema insurance 
-- ----------------------------------------------------- 
CREATE SCHEMA IF NOT EXISTS `insurance` DEFAULT CHARACTER SET utf8 ; 
USE `insurance` ; 

-- ----------------------------------------------------- 
-- 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; 


-- ----------------------------------------------------- 
-- Table `insurance`.`Policy Table` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Policy Table` (
    `Policy_ID` MEDIUMTEXT NOT NULL DEFAULT Auto Incrament, 
    `Policy Number` NVARCHAR(20) NOT NULL DEFAULT 'Policy Number', 
    `PolicyEffectiveDate` DATETIME NOT NULL DEFAULT Effective Date, 
    `PolicyExpireDate` DATETIME NOT NULL DEFAULT Policy Expire Date, 
    `PaymentOption` DATETIME NOT NULL DEFAULT Designated payment time, 
    `TotalAmount` DOUBLE NOT NULL DEFAULT Total policy amount, 
    `Active` TINYINT(1) NOT NULL DEFAULT If expired, false unless renew, 
    `AdditionalInfo` TEXT NULL DEFAULT 'Hidden info for staff', 
    `CreateDate` DATETIME NOT NULL, 
    `DriverAddress_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`Policy_ID`), 
    CONSTRAINT `fk_Policy Table_DriverAddress1` 
    FOREIGN KEY (`DriverAddress_ID`) 
    REFERENCES `insurance`.`DriverAddress` (`Address_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_Policy Table_DriverAddress1_idx` ON `insurance`.`Policy Table` (`DriverAddress_ID` ASC); 


-- ----------------------------------------------------- 
-- Table `insurance`.`PolicyEditLog` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`PolicyEditLog` (
    `Log_ID` MEDIUMTEXT NOT NULL DEFAULT Auto incrament, 
    `EditedTableName` VARCHAR(50) NOT NULL DEFAULT 'Name of the table when record is applied', 
    `EditedDate` DATETIME NOT NULL DEFAULT When is the record put into the DB, 
    `EditedBy` VARCHAR(50) NULL DEFAULT 'Who updated the record', 
    `AdditionalInfo` TEXT NULL DEFAULT 'Extra information for the staff', 
    `Policy Table_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`Log_ID`), 
    CONSTRAINT `fk_PolicyEditLog_Policy Table1` 
    FOREIGN KEY (`Policy Table_ID`) 
    REFERENCES `insurance`.`Policy Table` (`Policy_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_PolicyEditLog_Policy Table1_idx` ON `insurance`.`PolicyEditLog` (`Policy Table_ID` ASC); 


-- ----------------------------------------------------- 
-- Table `insurance`.`Payment Table` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Payment Table` (
    `Payment_ID` MEDIUMTEXT NOT NULL DEFAULT Auto incrament, 
    `PaidDate` DATETIME NOT NULL DEFAULT Payment made date, 
    `Amount` DOUBLE NOT NULL DEFAULT How much paid, 
    `PaymentMethod` VARCHAR(100) NULL DEFAULT 'What way it was paid', 
    `PaymentFirstName` VARCHAR(50) NULL DEFAULT 'First name on card', 
    `PaymentLastName` VARCHAR(50) NULL DEFAULT 'Last name on card', 
    `CardNumber` VARCHAR(50) NULL DEFAULT 'front number of the card', 
    `BackCode` VARCHAR(10) NULL DEFAULT 'three digits at the back of the card', 
    `CardExpiryDate` VARCHAR(10) NULL DEFAULT 'When does it expire', 
    `CardType` VARCHAR(20) NULL DEFAULT 'visa/maestro etc.', 
    `DebitOrCredit` VARCHAR(50) NULL DEFAULT 'Is it a debit or a credit card?', 
    `BankName` VARCHAR(100) NULL DEFAULT 'The actual name of the bank', 
    `AccountNumber` VARCHAR(20) BINARY NULL DEFAULT 'In case person decides to use DD', 
    `BankCode` VARCHAR(20) NULL DEFAULT 'The 6 digit area code of the bank', 
    `ChequeNumber` VARCHAR(20) NULL DEFAULT 'If it\'s been paid with a cheque', 
    `ChequeImage` VARCHAR(20) NULL DEFAULT 'Image of the cheque', 
    `AdditionalInfo` TEXT NULL DEFAULT 'Additional information', 
    `CreatedDate` DATETIME NULL DEFAULT When was the account created, 
    PRIMARY KEY (`Payment_ID`)) 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `insurance`.`Bill` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Bill` (
    `BILL_ID` MEDIUMTEXT NULL DEFAULT Auto incrament, 
    `DueDate` DATETIME NOT NULL DEFAULT Payment due date, 
    `MinimumPayment` DOUBLE NOT NULL DEFAULT Minimum payment or per bill payment, 
    `CreatedDate` DATETIME NOT NULL DEFAULT Bill generated date, 
    `Balance` VARCHAR(45) NOT NULL DEFAULT 'Remaining balance if part payment is made', 
    `Status` NVARCHAR(50) NOT NULL DEFAULT 'Paid/Unpaid', 
    `Policy Table_ID` MEDIUMTEXT NOT NULL, 
    `Payment Table_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`BILL_ID`), 
    CONSTRAINT `fk_Bill_Policy Table` 
    FOREIGN KEY (`Policy Table_ID`) 
    REFERENCES `insurance`.`Policy Table` (`Policy_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_Bill_Payment Table1` 
    FOREIGN KEY (`Payment Table_ID`) 
    REFERENCES `insurance`.`Payment Table` (`Payment_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_Bill_Policy Table_idx` ON `insurance`.`Bill` (`Policy Table_ID` ASC); 

CREATE INDEX `fk_Bill_Payment Table1_idx` ON `insurance`.`Bill` (`Payment Table_ID` ASC); 


-- ----------------------------------------------------- 
-- Table `insurance`.`Driver` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Driver` (
    `Driver_ID` MEDIUMTEXT NOT NULL DEFAULT Primary Key, 
    `Title` VARCHAR(50) NULL DEFAULT 'Mr, Mrs etc.', 
    `FirstName` VARCHAR(50) NOT NULL DEFAULT 'Name of the driver', 
    `SurName` VARCHAR(50) NOT NULL DEFAULT 'Surname of the driver', 
    `MiddleInitial` VARCHAR(1) NULL DEFAULT '1 letter of the middle name', 
    `DoB` VARCHAR(20) NOT NULL DEFAULT 'Date of birth', 
    `EmailAddress` VARCHAR(100) NULL DEFAULT 'Can be null if user doesnt have one', 
    `PhoneNumber` VARCHAR(20) NOT NULL DEFAULT 'Driver Home Phone number', 
    `MobileNumber` VARCHAR(20) NOT NULL DEFAULT 'Mobile number', 
    `LicenseIssuedDate` DATE NOT NULL DEFAULT License issued date, 
    `LicenseCountry` VARCHAR(50) NOT NULL DEFAULT 'where is the license from', 
    `LicenseNumber` VARCHAR(20) NOT NULL DEFAULT 'Driver license number', 
    `Gender` VARCHAR(10) NOT NULL DEFAULT 'Sex', 
    `MartialStatus` VARCHAR(20) NOT NULL DEFAULT 'Martial Status', 
    `CreatedDate` DATETIME NOT NULL DEFAULT When was it created, 
    `Active` TINYINT(1) NULL DEFAULT if driver is still using services or not, 
    `Policy Table_ID` MEDIUMTEXT NOT NULL, 
    `DriverAddress_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`Driver_ID`), 
    CONSTRAINT `fk_Driver_Policy Table1` 
    FOREIGN KEY (`Policy Table_ID`) 
    REFERENCES `insurance`.`Policy Table` (`Policy_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_Driver_DriverAddress1` 
    FOREIGN KEY (`DriverAddress_ID`) 
    REFERENCES `insurance`.`DriverAddress` (`Address_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_Driver_Policy Table1_idx` ON `insurance`.`Driver` (`Policy Table_ID` ASC); 

CREATE INDEX `fk_Driver_DriverAddress1_idx` ON `insurance`.`Driver` (`DriverAddress_ID` ASC); 


-- ----------------------------------------------------- 
-- Table `insurance`.`Vehicle` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Vehicle` (
    `Vehicle_ID` MEDIUMTEXT NOT NULL DEFAULT Auto incrament, 
    `Year` CHAR(4) NOT NULL DEFAULT 'year', 
    `Make` VARCHAR(50) NOT NULL DEFAULT 'make', 
    `model` VARCHAR(50) NOT NULL DEFAULT 'model', 
    `Colour` VARCHAR(50) NOT NULL DEFAULT 'colour', 
    `Mileage` INT(11) NOT NULL DEFAULT mileage, 
    `number plate` VARCHAR(20) NOT NULL DEFAULT 'number plate', 
    `CreatedDate` VARCHAR(50) NOT NULL DEFAULT 'when was this car added', 
    `Additional notes` VARCHAR(100) NULL DEFAULT 'If necessary for example requires repair etc.', 
    `Active` TINYINT(1) NULL DEFAULT Has vehicle been removed or not, 
    `Policy Table_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`Vehicle_ID`), 
    CONSTRAINT `fk_Vehicle_Policy Table1` 
    FOREIGN KEY (`Policy Table_ID`) 
    REFERENCES `insurance`.`Policy Table` (`Policy_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_Vehicle_Policy Table1_idx` ON `insurance`.`Vehicle` (`Policy Table_ID` ASC); 


-- ----------------------------------------------------- 
-- Table `insurance`.`Vehicle_Driver` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Vehicle_Driver` (
    `Incrament_ID` MEDIUMTEXT NOT NULL DEFAULT Auto Incrament, 
    `CarPurpose` BIT NULL DEFAULT Is it for business or personal, 
    `PredictedMilage` INT NULL DEFAULT How many miles do you expect to drive, 
    `CreatedDate` DATETIME NULL DEFAULT when was it added, 
    `Active` TINYINT(1) NULL DEFAULT Is it active/deactivated, 
    PRIMARY KEY (`Incrament_ID`)) 
ENGINE = InnoDB; 


-- ----------------------------------------------------- 
-- Table `insurance`.`Coverage` 
-- ----------------------------------------------------- 
CREATE TABLE IF NOT EXISTS `insurance`.`Coverage` (
    `Coverage_ID` MEDIUMTEXT NOT NULL DEFAULT Auto increment, 
    `CoverageName` VARCHAR(100) NULL DEFAULT 'Name of coverage', 
    `CoverageGroup` VARCHAR(50) NOT NULL DEFAULT 'Rental, jobless, gap etc.', 
    `Code` VARCHAR(20) NOT NULL DEFAULT 'Group for each business option', 
    `IsPolicyCoverage` BIT NOT NULL DEFAULT Does it apply only for the policy coverage, 
    `IsVehicleCoverage` BIT NOT NULL DEFAULT Doesi t apply only for the vehicle coverage, 
    `DriverStatus` VARCHAR(45) NULL DEFAULT 'His current driver rating', 
    `Description` BIT NULL DEFAULT additional info, 
    `PolicyEditLog_ID` MEDIUMTEXT NOT NULL, 
    `Vehicle_Driver_ID` MEDIUMTEXT NOT NULL, 
    PRIMARY KEY (`Coverage_ID`), 
    CONSTRAINT `fk_Coverage_PolicyEditLog1` 
    FOREIGN KEY (`PolicyEditLog_ID`) 
    REFERENCES `insurance`.`PolicyEditLog` (`Log_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION, 
    CONSTRAINT `fk_Coverage_Vehicle_Driver1` 
    FOREIGN KEY (`Vehicle_Driver_ID`) 
    REFERENCES `insurance`.`Vehicle_Driver` (`Incrament_ID`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB; 

CREATE INDEX `fk_Coverage_PolicyEditLog1_idx` ON `insurance`.`Coverage` (`PolicyEditLog_ID` ASC); 

CREATE INDEX `fk_Coverage_Vehicle_Driver1_idx` ON `insurance`.`Coverage` (`Vehicle_Driver_ID` ASC); 


SET [email protected]_SQL_MODE; 
SET [email protected]_FOREIGN_KEY_CHECKS; 
SET [email protected]_UNIQUE_CHECKS; 

Ich werde sehr dankbar, wenn mir jemand in die richtige Richtung führen könnte.

+0

Es gibt eine Menge von Inkonsistenzen und Fehler, so dass ich denke, Sie sollten mit einem Tisch schreibe dies von vorn beginnen Zu einer Zeit, bestätigen Sie, dass es funktioniert, dann gehen Sie weiter zum nächsten. Oder verwenden Sie stattdessen die Workbench-Modellierung und generieren Sie dann SQL. Zum Beispiel ist "Autoinkrement" ein Tippfehler. Außerdem scheint es, dass Sie Kommentare mit Standardwerten mischen und einige in Anführungszeichen, andere dagegen nicht. –

Antwort

1

Sie haben STANDARD Primärschlüssel .. versuchen stattdessen ohne Standard in der ersten Reihe zB: AUTO_INCREMENT oder nichts

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 
Verwandte Themen