简体   繁体   English

MySQL多次插入语句未添加所有记录

[英]Mysql multiple insert statement not adding all records

I'm inserting a max of 3000 records and for this I just wrote a single query like 我最多插入3000条记录,为此,我只写了一个查询,例如

insert into p_code (id_user_staff,user_id,postalcode,dropDownGroup) 
values 
(187,51,'AB10',1), 
(187,51,'AB11',1), 
(187,51,'AB12',1), 
(187,51,'AB13',1), 
(187,51,'AB14',1), 
(187,51,'AB15',1), 
(187,51,'AB16',1), 
(187,51,'AB21',1), .........3000

This seems to be working fine, but it's not adding all records, many of them are missed. 这似乎工作正常,但是并没有添加所有记录,很多记录都被遗漏了。 I've also tried the same with each single query in for loop but this also is not adding all records. 对于for循环中的每个单个查询,我也尝试过相同的操作,但这也未添加所有记录。

I've also tried the same with each single query in for loop but this also is not adding all records. 对于for循环中的每个单个查询,我也尝试过相同的操作,但这也未添加所有记录。

Obviously the insert statement is fine then. 显然,插入语句就可以了。
There is some constraint on the table that is preventing some values from being inserted. 表上存在一些约束,阻止了某些值的插入。

This is either a unique or primary key. 这是唯一键或主键。 On one or more of the fields: 在一个或多个字段上:
id_user_staff, user_id, dropDownGroup

Or a foreign key constaint that is not met on an insert. 或插入中未满足的外键约束。

Or a trigger that fires before the insert and that generates an error, thereby preventing the insert from being finalized. 或者触发器在插入before触发并产生错误,从而阻止插入被最终确定。

If you do the big insert statement, you can use: 如果执行大插入语句,则可以使用:

SHOW ERRORS; 

Afterwards that will give you the exact error(s) which is stopping the insert(s). 之后,这将为您提供确切的错误,这将停止插入。

See: http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html 参见: http : //dev.mysql.com/doc/refman/5.0/en/show-warnings.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM