尝试将数据插入表中时出错

时间:2012-12-30 11:08:07

标签: sql insert create-table

尝试将数据插入表格时出现此错误。

  

列数与第3行的值计数不匹配

这是我要插入的数据:

INSERT INTO shirts_link (adult, kids, babies, shirt_id, size_id, price_id) VALUES
    ('n','n','y','1','1','1'),('n','n','y','1','2','1'),('n''n','y','1','3','1'),('n','n','y','1','4','1'),
    ('n','n','y','1','5','1'),('n','n','y','1','6','1'),('n','n','y','1','7','1'),('n','n','y','1','8','1'),
    ('n','y','n','1','9','1'),('y','y','n','1','10','1'),('y','y','n','1','11','1'),('y','y','n','1','12','1'),
    ('y','y','n','1','13','1'),('y','n','n','1','14','2'),('y','n','n','1','15','3'),('y','n','n','1','16','4'),
    ('y','n','n','1','17','5'),

    ('y','n','n','2','10','6'),('y','n','n','2','11','6'),('y','n','n','2','12','6'),('y','n','n','2','13','6'),
    ('y','n','n','2','14','7'),('y','n','n','2','15','8'),('y','n','n','2','16','9'),('y','n','n','2','17','10'),

    ('y','n','n','3','10','11'),('y','n','n','3','11','11'),('y','n','n','3','12','11'),('y','n','n','3','13','11'),
    ('y','n','n','3','14','11'),

    ('y','y','n','4','10','12'),('y','y','n','4','11','12'),('y','y','n','4','12','12'),('y','y','n','4','13','12'),
    ('y','n','n','4','14','13'),('y','n','n','4','15','14'),

    ('y','y','n','5','10','15'),('y','y','n','5','11','15'),('y','y','n','5','12','15'),('y','y','n','5','13','15'),
    ('y','n','n','5','14','16'),('y','n','y','5','15','17'),

    ('y','y','n','6','10','18'),('y','y','n','6','11','18'),('y','y','n','6','12','18'),('y','y','n','6','13','18'),
    ('y','n','n','6','14','19'),

    ('y','y','n','7','10','20'),('y','y','n','7','11','20'),('y','y','n','7','12','20'),('y','y','n','7','13','20'),
    ('y','n','n','7','14','21'),

    ('y','n','n','8','10','22'),('y','n','n','8','11','22'),('y','n','n','8','12','22'),('y','n','n','8','13','22'),
    ('y','n','n','8','14','23'),

    ('n','n','y','9','5','24'),('n','n','y','9','6','24'),('n','n','y','9','6','24'),('n','n','y','9','7','24'),
    ('n','n','y','9','8','24'),('y','y','n','9','9','24'),('y','y','n','9','10','24'),('y','y','n','9','11','24'),
    ('y','y','n','9','12','24'),('y','y','n','9','13','24'),('y','n','n','9','14','25'),('y','n','n','9','15','26'),
    ('y','n','n','9','16','25'),

    ('n','n','y','10','1','1'),('n','n','y','10','2','1'),('n','n','y','10','3','1'),('n','n','y','10','4','1');

以下是表格的设置方式:

CREATE TABLE shirts_link (
    adult VARCHAR(1) NOT NULL,
    kids VARCHAR(1) NOT NULL,
    babies VARCHAR(1) NOT NULL,
    shirt_id INT UNSIGNED NOT NULL,
    size_id INT UNSIGNED NOT NULL,
    price_id INT UNSIGNED NOT NULL,
    PRIMARY KEY (shirt_id,size_id,price_id),
    FOREIGN KEY (`shirt_id`) REFERENCES `shirts`(`id`),
    FOREIGN KEY (`size_id`) REFERENCES shirt_sizes(`id`),
    FOREIGN KEY (`price_id`) REFERENCES shirt_prices(`id`)
    )ENGINE=INNODB;

我做错了什么?

2 个答案:

答案 0 :(得分:4)

查看第3行的记录,你有这组值,

('n''n','y','1','3','1')
    ^ HERE

在其上添加逗号。

('n','n','y','1','3','1')

它不会返回语法错误,因为它实际上是有效的。它只是逃避单引号。如果成功执行,将插入的值为

n'n

答案 1 :(得分:2)

看起来你错过了一个逗号。

应为('n','n','y','1','3','1')