使用MySQL批量插入数据库表数据

发布于 2024-12-28 08:32:53 字数 402 浏览 5 评论 0原文

我正在使用 MySQL 将多个条目上传到我们数据库的表中。但是,以下命令不起作用并引发此错误“#1136 - 列计数与第 1 行的值计数不匹配”...这很奇怪,因为下面包含 4 列:

(我刚刚在此处包含了两个结果作为数据示例)

INSERT INTO state (state_id,country_id,state_name,active) VALUES (152,153),(5),(Test1,Test2),(1)

这应该形成多行,最终如下所示:

state_id |国家/地区 ID |州名 |积极的 152 5 测试 1 1 153 5 Test 2 1

(看起来像编辑中的表格...但此处未呈现,抱歉!)

I'm uploading multiple entries into a table in our database using MySQL. However, the following command does not work and throws up this error "#1136 - Column count doesn't match value count at row 1"... which is odd as there are 4 columns as included below:

(I've just included two of the results here as an example of the data)

INSERT INTO state (state_id,country_id,state_name,active) VALUES (152,153),(5),(Test1,Test2),(1)

This should form multiple rows and eventually look like this:

state_id | country_id | state_name | active
152 5 Test 1 1
153 5 Test 2 1

(that looks like a table in the edit... but not rendered on here, sorry!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兔小萌 2025-01-04 08:32:54

如果定义了 4 列,则还必须在 VALUES 之后放置 4 个值的组。

After VALUES you also have to put groups of 4 values if you defined 4 columns.

瞄了个咪的 2025-01-04 08:32:54

试试这个:

INSERT INTO state (state_id,country_id,state_name,active) VALUES ('(152,153)','(5)','(Test1,Test2)','(1)')

Try this:

INSERT INTO state (state_id,country_id,state_name,active) VALUES ('(152,153)','(5)','(Test1,Test2)','(1)')
三月梨花 2025-01-04 08:32:53

要插入多行,您需要为每行提供正确数量的值。

语法是这样的:您指定一行接着另一行,而不是列:

INSERT INTO state 
(state_id,country_id,state_name,active) 
VALUES 
(152,5,'Test1',1), 
(153,5,'Test2',1);

To insert multiple rows, you need to supply the correct number of values for each row.

The syntax is such that you specify one row after the other, not columns:

INSERT INTO state 
(state_id,country_id,state_name,active) 
VALUES 
(152,5,'Test1',1), 
(153,5,'Test2',1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文