继续收到此错误:查询无效:键'PRIMARY'重复输入'0'

时间:2012-08-04 20:54:05

标签: php mysql

这是我创建数据库的脚本。在此先感谢大家的帮助。

发生错误时我插入数据的四个表是:

  1. 资产
  2. asset_details
  3. 位置
  4. 发票

  5. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
    
    DROP SCHEMA IF EXISTS `inventory1` ;
    CREATE SCHEMA IF NOT EXISTS `inventory1` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
    USE `inventory1` ;
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`department`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`department` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`department` (
      `department_id` INT NOT NULL ,
      `department_name` VARCHAR(45) NOT NULL ,
      `job_id` VARCHAR(45) NOT NULL ,
      PRIMARY KEY (`department_id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`employee`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`employee` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`employee` (
      `employee_id` INT NULL ,
      `department_id` INT NULL ,
      `fname` VARCHAR(45) NULL ,
      `lname` VARCHAR(45) NULL ,
      `email` VARCHAR(45) NULL ,
      `phone_number` VARCHAR(45) NULL ,
      `hire_date` VARCHAR(45) NULL ,
      `job_id` VARCHAR(45) NULL ,
      `manager_id` VARCHAR(45) NULL ,
      PRIMARY KEY (`employee_id`) ,
      INDEX `department_id` (`department_id` ASC) ,
      CONSTRAINT `department_id`
        FOREIGN KEY (`department_id` )
        REFERENCES `inventory1`.`department` (`department_id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`invoice`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`invoice` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`invoice` (
      `invoice_number` VARCHAR(25) NULL ,
      `invoice_date` INT UNSIGNED NULL ,
      `purchase_price` INT UNSIGNED NULL ,
      `quantity` INT UNSIGNED NULL ,
      `order_date` INT UNSIGNED NULL ,
      `vender` INT UNSIGNED NULL ,
      `warranty_end` DATE NULL ,
      `notes` VARCHAR(255) NULL ,
      `vender_name` VARCHAR(45) NULL ,
      PRIMARY KEY (`invoice_number`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`assignment`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`assignment` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`assignment` (
      `assignment_id` INT NOT NULL ,
      `assignment_status` VARCHAR(45) NOT NULL ,
      PRIMARY KEY (`assignment_id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`asset`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`asset` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`asset` (
      `asset_tag` INT NOT NULL ,
      `cap_ex` VARCHAR(10) NULL ,
      `asset_type_id` INT NULL ,
      `invoice_number` VARCHAR(25) NULL ,
      `status_id` INT NULL ,
      PRIMARY KEY (`asset_tag`) ,
      INDEX `assignment_id` (`status_id` ASC) ,
      CONSTRAINT `invoice_number`
        FOREIGN KEY (`invoice_number` )
        REFERENCES `inventory1`.`invoice` (`invoice_number` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `assignment_id`
        FOREIGN KEY (`status_id` )
        REFERENCES `inventory1`.`assignment` (`assignment_id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`location`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`location` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`location` (
      `location_id` INT NOT NULL ,
      `location_name` VARCHAR(45) NULL ,
      `rack` INT NULL ,
      `row` INT NULL ,
      `unit` INT NULL ,
      PRIMARY KEY (`location_id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`physical_asset`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`physical_asset` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`physical_asset` (
      `physical_asset_id` INT NOT NULL ,
      `location_id` INT NOT NULL ,
      `employee_id` INT NOT NULL ,
      `physical_asset_name` VARCHAR(45) NOT NULL ,
      PRIMARY KEY (`physical_asset_id`) ,
      INDEX `location_id` (`location_id` ASC) ,
      INDEX `employee_id` (`employee_id` ASC) ,
      CONSTRAINT `location_id`
        FOREIGN KEY (`location_id` )
        REFERENCES `inventory1`.`location` (`location_id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `employee_id`
        FOREIGN KEY (`employee_id` )
        REFERENCES `inventory1`.`employee` (`employee_id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `inventory1`.`asset_details`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `inventory1`.`asset_details` ;
    
    CREATE  TABLE IF NOT EXISTS `inventory1`.`asset_details` (
      `asset_type_id` INT NULL ,
      `asset-tag` INT NULL ,
      `asset_type` VARCHAR(45) NULL ,
      `physical_asset_id` INT NULL ,
      `manufacturer` VARCHAR(45) NULL ,
      `os` VARCHAR(45) NULL ,
      `os_version` VARCHAR(45) NULL ,
      `make` VARCHAR(45) NULL ,
      `model` VARCHAR(45) NULL ,
      `serial_number` VARCHAR(45) NULL ,
      `processor` VARCHAR(45) NULL ,
      `ram` VARCHAR(45) NULL ,
      `memory` VARCHAR(45) NULL ,
      `hdd` VARCHAR(45) NULL ,
      `host_name` VARCHAR(45) NULL ,
      `notes` VARCHAR(250) NULL ,
      PRIMARY KEY (`asset_type_id`) ,
      INDEX `physical_asset_id` (`physical_asset_id` ASC) ,
      INDEX `asset_tag` (`asset-tag` ASC) ,
      CONSTRAINT `physical_asset_id`
        FOREIGN KEY (`physical_asset_id` )
        REFERENCES `inventory1`.`physical_asset` (`physical_asset_id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `asset_tag`
        FOREIGN KEY (`asset-tag` )
        REFERENCES `inventory1`.`asset` (`asset_tag` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    
    SET SQL_MODE=@OLD_SQL_MODE;
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
    

1 个答案:

答案 0 :(得分:2)

您需要确保在主键上使用AUTO_INCREMENT,否则它会尝试将它们全部设为0,但它不能,因为主键必须是唯一的。