【问题标题】:Error 1136 in MySQL when inserting data with the columns correct插入列正确的数据时 MySQL 出现错误 1136
【发布时间】:2018-09-27 13:21:59
【问题描述】:

我正在为一个学校项目开发数据库,​​每次我将数据插入表中时,我都会得到以下信息。

错误代码:1136。列计数与第 1 行的值计数不匹配

我发现这是由具有与表本身不同数量的值的值之后的行引起的。 在我的数据库中,我已经验证了行数是有效的。

为了缩短这个时间,我只包含了一张表的信息,但我拥有的所有表都会发生这种情况。

DROP schema if exists `ACRS`;
CREATE SCHEMA IF NOT EXISTS `ACRS` DEFAULT CHARACTER SET utf8;
USE `ACRS`;

DROP TABLE IF EXISTS ComputerDetails;
CREATE TABLE IF NOT EXISTS ComputerDetails (
    `ComputerNumber`    INT         NOT NULL,
    `ComputerYear`      INT         NULL,
    `ComputerModel`     VARCHAR(45) NULL,
    `CPUModel`          VARCHAR(25) NULL,
    `HasMonitor`        CHAR(1)     NULL,
    `NumOfUSB`          INT         NULL,
    `HardDriveCapGB`    INT         NULL,
    `NetworkCardType`   VARCHAR(45) NULL,
    `OperatingSystem`   VARCHAR(45) NULL,
    `HasWebcam`         CHAR(1)     NULL,
    PRIMARY KEY         (`ComputerNumber`))
ENGINE = InnoDB;

INSERT INTO ComputerDetails
(   ComputerNumber,     ComputerYear,   ComputerModel,                                  CPUModel,   HasMonitor,     NumOfUSB,   HardDriveCapGB,     NetworkCardType,    OperatingSystem,    HasWebCam)
values(
(   0101,               2008,           'Dell Optoplez 980',        'Intel',    'Y',            3,          100,                'Both',         'Windows',          'Y'),
(   0102,               1985,           'IBM PS2',                  'Intel'     'N',            0,          0,                  'Wireless',     'Unix',             'Y'),
(   0103,               2011,           'Apple MacBook Pro',        'Intel'     'Y',            2,          100,                'Both',         'Mac',              'N'),
(   0104,               2011,           'Apple MacBook Pro',        'Intel'     'N',            4,          1000,               'Wired',        'Windows',          'N'),
(   0105,               2014,           'Toshiba Satellite P50A',   'AMD'       'Y',            2,          150,                'Wireless',     'Linux',            'Y'),
(   0106,               2013,           'VersaPro type VC' 'Intel', 'Intel'     'Y',            3,          105,                'Both',         'Unix',             'N'),
(   0107,               1999,           'Power Mac G3',             'Power PC'  'N',            3,          5,                  'Both',         'Mac',              'Y'),
(   0108,               2007,           'Mac Pro',                  'Intel'     'Y',            4,          200,                'Wireless',     'Mac',              'N'),
(   0109,               2000,           'Power Mac x86',            'Intel'     'Y',            4,          600,                'Wired',        'Windows',          'Y'),
(   0110,               2018,           'Apple iMac 4K',            'Intel'     'Y',            3,          50000,              'Both',         'Mac/Windows',      'Y'),
(   0111,               2013,           'VersaPro type VC',         'AMD'       'Y',            3,          640,                'Both',         'Unix',             'Y'),
(   0112,               2016,           'iMac',                     'Intel'     'Y',            4,          630,                'Wireless',     'Unix',             'Y'),
(   0113,               2013,           'VersaPro type VC',         'Intel'     'Y',            3,          250,                'Wired',        'Windows',          'N'),
(   0114,               2015,           'Sony VAIO Z',              'Intel'     'Y',            17,         2,                  'Both',         'Mac',              'N'),
(   0115,               1999,           'Power Mac G3',             'Power PC'  'N',            2,          30,                 'Wired',        'Mac',              'N'),
(   0116,               2013,           'VersaPro type VC',         'Intel'     'Y',            4,          350,                'Both',         'Windows',          'Y'),
(   0117,               2008,           'Dell Optoplez 980',        'Intel'     'Y',            3,          150,                'Both',         'Linux',            'Y'),
(   0118,               2008,           'Dell Optoplez 980',        'Intel'     'Y',            1,          200,                'Wireless',     'Linux',            'Y'),
(   0119,               2010,           'Toshiba Satellite 750',    'Intel'     'Y',            2,          140,                'Both',         'Unix',             'Y'),
(   0120,               2018,           'HP Z2 Mini G3',            'AMD'       'Y',            3,          500,                'Wired',        'Unix',             'N')
);

【问题讨论】:

  • PRIMARY KEY 是否自动递增?

标签: mysql database schema mysql-workbench sql-insert


【解决方案1】:

通过删除 VALUES 中的额外的开始和结束圆括号尝试以下查询,首先在 PhpMYAdmin 上运行它...希望这会有所帮助

INSERT INTO ComputerDetails
(   ComputerNumber,     ComputerYear,   ComputerModel,                                  CPUModel,   HasMonitor,     NumOfUSB,   HardDriveCapGB,     NetworkCardType,    OperatingSystem,    HasWebCam)
values
(   0101,               2008,           'Dell Optoplez 980',        'Intel',    'Y',            3,          100,                'Both',         'Windows',          'Y'),
(   0102,               1985,           'IBM PS2',                  'Intel'     'N',            0,          0,                  'Wireless',     'Unix',             'Y'),
(   0103,               2011,           'Apple MacBook Pro',        'Intel'     'Y',            2,          100,                'Both',         'Mac',              'N'),
(   0104,               2011,           'Apple MacBook Pro',        'Intel'     'N',            4,          1000,               'Wired',        'Windows',          'N'),
(   0105,               2014,           'Toshiba Satellite P50A',   'AMD'       'Y',            2,          150,                'Wireless',     'Linux',            'Y'),
(   0106,               2013,           'VersaPro type VC' 'Intel', 'Intel'     'Y',            3,          105,                'Both',         'Unix',             'N'),
(   0107,               1999,           'Power Mac G3',             'Power PC'  'N',            3,          5,                  'Both',         'Mac',              'Y'),
(   0108,               2007,           'Mac Pro',                  'Intel'     'Y',            4,          200,                'Wireless',     'Mac',              'N'),
(   0109,               2000,           'Power Mac x86',            'Intel'     'Y',            4,          600,                'Wired',        'Windows',          'Y'),
(   0110,               2018,           'Apple iMac 4K',            'Intel'     'Y',            3,          50000,              'Both',         'Mac/Windows',      'Y'),
(   0111,               2013,           'VersaPro type VC',         'AMD'       'Y',            3,          640,                'Both',         'Unix',             'Y'),
(   0112,               2016,           'iMac',                     'Intel'     'Y',            4,          630,                'Wireless',     'Unix',             'Y'),
(   0113,               2013,           'VersaPro type VC',         'Intel'     'Y',            3,          250,                'Wired',        'Windows',          'N'),
(   0114,               2015,           'Sony VAIO Z',              'Intel'     'Y',            17,         2,                  'Both',         'Mac',              'N'),
(   0115,               1999,           'Power Mac G3',             'Power PC'  'N',            2,          30,                 'Wired',        'Mac',              'N'),
(   0116,               2013,           'VersaPro type VC',         'Intel'     'Y',            4,          350,                'Both',         'Windows',          'Y'),
(   0117,               2008,           'Dell Optoplez 980',        'Intel'     'Y',            3,          150,                'Both',         'Linux',            'Y'),
(   0118,               2008,           'Dell Optoplez 980',        'Intel'     'Y',            1,          200,                'Wireless',     'Linux',            'Y'),
(   0119,               2010,           'Toshiba Satellite 750',    'Intel'     'Y',            2,          140,                'Both',         'Unix',             'Y'),
(   0120,               2018,           'HP Z2 Mini G3',            'AMD'       'Y',            3,          500,                'Wired',        'Unix',             'N');

【讨论】:

    【解决方案2】:

    问题最终是缺少逗号。我的错。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多