CREATE TABLE invoices(
invoice_id INT PRIMARY KEY,
category_id INT NOT NULL,
supplier_id INT NOT NULL,
invoice_due_date VARCHAR(12),
invoice_supplier VARCHAR(255) NOT NULL,
invoice_contact VARCHAR(255) NOT NULL,
invoice_amount INT,
invoice_paid BOOL DEFAULT FALSE,
CONSTRAINT invoice_fk_supplier
FOREIGN KEY(supplier_id)
REFERENCES suppliers(supplier_id),
CONSTRAINT invoice_fk_category
FOREIGN KEY(category_id)
REFERENCES categories(category_id)
);
INSERT INTO invoices(invoice_id, category_id, supplier_id,
invoice_supplier, invoice_due_date, invoice_contact, invoice_amount,
invoice_paid) VALUES
(1, 2, 1, "Pepsi" '12-24-2017', 'James Hatfield', 23500, FALSE),
(2, 2, 2, "Ragu", '12-20-2017', 'Mike Richards', 8650, FALSE),
(3, 2, 3, "Miguel's Produce", '12-18-2017', 'Miguel Profesa', 6750,
FALSE),
(4, 2, 4, "Butch's Butcher Shop", '12-15-2017', 'Rick Santana', 9550,
FALSE),
(5, 2, 5, "Cafe Carmen", '12-04-2017', 'Carmen San Diego', 1250, FALSE);
我正在使用MySQL WorkBench 6.3,我一直收到此错误
" 错误代码: 1136.列数与第1行和第34行的值计数不匹配;
每当我尝试运行INSERT语句将数据添加到数据库时。我的其他表没有问题,只有这一个。但是,当我查找此错误时,似乎很多时候错误归结为没有匹配数量的值到记录,但我已经三次检查我有8个字段和8个值。
如果有人可以帮我解释或解释它,我会非常感激,因为这让我难以忍受了几个小时。
干杯!
答案 0 :(得分:1)
首先是"百事可乐" ' 2017年12月24日'在.typo错误之间没有逗号
(1,2,1," Pepsi"' 12-24-2017',' James Hatfield',23500,FALSE),
第二个 您的第四列是VARCHAR(12)&不是VARCHAR(255)
主键插入有很多冲突......为了安全起见...保持PK自动
CREATE TABLE invoices(
invoice_id INT NOT NULL AUTO_INCREMENT,
category_id INT NOT NULL,
supplier_id INT NOT NULL,
invoice_due_date VARCHAR(255),
invoice_supplier VARCHAR(255) NOT NULL,
invoice_contact VARCHAR(255) NOT NULL,
invoice_amount INT,
invoice_paid BOOL DEFAULT FALSE,
CONSTRAINT invoice_fk_supplier
FOREIGN KEY(supplier_id)
REFERENCES suppliers(supplier_id),
CONSTRAINT invoice_fk_category
FOREIGN KEY(category_id)
REFERENCES categories(category_id)
);
然后执行类似..
的插入 INSERT INTO invoices( category_id, supplier_id,
invoice_supplier, invoice_due_date, invoice_contact, invoice_amount,
invoice_paid) VALUES
( 2, 1, "Pepsi", "12-24-2017", "James Hatfield", 23500, FALSE)