Im not exactly sure how, but I’ve ended up with duplicates.
In the current table, you’ll see that I used chapt_id as the PK. This allowed for duplicate chapters in some movies.
CREATE TABLE IF NOT EXISTS `chapters` (
`chapt_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`mov_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`chapter_num` varchar(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`chapter_title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`chapt_id`),
KEY `mov_id` (`mov_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
You can see here, if I export from the chapters table
INSERT INTO `chapters` VALUES
(1996, 65, '1', 'Main Titles'),
(1997, 65, '2', 'The Prisoners Arrive'),
(1998, 65, '3', 'Escape Attempt 1'),
(1999, 65, '4', 'The Blind Spot'),
(2000, 65, '5', 'To the Cooler'),
(2001, 65, '6', 'Bartlett''s Arrival'),
(2002, 65, '7', 'The Objective'),
(2003, 65, '8', 'The Escape Committee'),
(2004, 65, '9', 'Forger & Scrounger'),
(2005, 65, '10', 'Stealing Steel'),
(322864, 65, '1', 'Main Titles'),
(322865, 65, '2', 'The Prisoners Arrive'),
(322866, 65, '3', 'Escape Attempt 1'),
(322867, 65, '4', 'The Blind Spot'),
(322868, 65, '5', 'To the Cooler'),
(322869, 65, '6', 'Bartlett''s Arrival'),
(322870, 65, '7', 'The Objective'),
(322871, 65, '8', 'The Escape Committee'),
(322872, 65, '9', 'Forger & Scrounger'),
(322873, 65, '10', 'Stealing Steel');
I’m trying to take the data from the current “chapters” table and INSERT it into the new “movies_chapters” table. Obviously, looking at the PKs below you can see that I’m running into duplicate errors.
CREATE TABLE IF NOT EXISTS `movies_chapters` (
`mc_mov_id` int(10) unsigned NOT NULL DEFAULT '0',
`mc_lang` char(2) CHARACTER SET latin1 NOT NULL,
`mc_chapter_num` varchar(3) CHARACTER SET latin1 NOT NULL,
`mc_chapter_title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`mc_mov_id`,`mc_chapter_num`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I’ll be using the mov_id and the chapter_num as the new PK, so I’m not worried about keeping the chapt_id anymore. What’s the best way to handle this? Delete the duplicates from the chapters table? If so, how?
Thanks!