2016-07-24 149 views
0

我只是有50K + SQL查询,像这样:SQL INSERT INTO自动放ID

INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES 
(357, 1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '038;p=357', 0, 'autoblog_artykuly', '', 0); 

(...) 

INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES 
(357, 1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '38;p=357', 0, 'autoblog_artykuly', '', 0); 

所有查询具有相同的ID,当我尝试通过phpMyAdmin的把它添加到数据库中,我得到这个信息:

#1062 - Duplicate entry '357' for key 'PRIMARY' 

用什么更改ID:357来放置自动值?自动递增?

+0

代码显然是MySQL,所以我删除了sql-server标记。请适当地标记问题。 –

+1

是的,将列更改为'AUTOINCREMENT'并且不提供'ID'值。 – David

回答

1

您应该将ID设置为UNIQUEAUTO-INCREMENT并将其从INSERT语句中删除。你不应该担心这个ID,它应该由MySQL本身来处理。

INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES 
(1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '038;p=357', 0, 'autoblog_artykuly', '', 0); 
-1

您的错误显示您在表设计时设置主键,以便发生此错误。如果你想设置自动增量,那么你只需在一列设置UNIQUE INDEX。