2016-07-24 11 views
0

ich habe nur 50k + SQL-Abfragen wie folgt aus:SQL INSERT INTO Auto put 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); 

Alle Anfragen haben die gleiche ID und wenn ich versuche, dies über phpMyAdmin Datenbank hinzuzufügen bekomme ich diese Informationen:

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

Mit welcher ID: 357 um Auto-Werte zu setzen? AUTOAUFKOMMEN?

+0

Der Code ist eindeutig MySQL, also habe ich das SQL-Server-Tag entfernt. Bitte kennzeichnen Sie die Fragen entsprechend. –

+1

Ja, ändern Sie die Spalte in 'AUTOINCREMENT' und geben Sie keinen' ID'-Wert ein. – David

Antwort

1

Sie sollten die ID UNIQUE und AUTO-INCREMENT einrichten und aus der INSERT-Anweisung entfernen. Sie sollten sich nie um die ID kümmern müssen, sie sollte von MySQL selbst behandelt werden.

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

Ihr Fehler zeigt an, dass Sie den Primärschlüssel in der Tabellenentwurfszeit gesetzt haben, so dass dieser Fehler auftritt. Wenn Sie die automatische Inkrementierung festlegen möchten, legen Sie einfach UNIQUE INDEX für eine Spalte fest.