Reputation: 170
I have a table topic which is having id and name id is primary. It has already data from ID 1 to 6.
I added one new column other. I want to load data from list.txt file into it and that should be from ID 1 to 6.
My list.txt is having:
apple
banana
orange
kiwi
My table:
CREATE TABLE `topics` (
`id` int(11) UNSIGNED NOT NULL,
`name` varchar(255) DEFAULT NULL,
`other` varchar(500) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `topics` (`id`, `name`, `other`) VALUES
(1, 'Accessories', ''),
(2, 'Cover', ''),
(3, 'Logos', ''),
(4, 'Story', ''),
(5, 'Editing', ''),
(6, 'Gaming', '');
ALTER TABLE `topics`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `id` (`id`),
ADD KEY `name` (`name`);
ALTER TABLE `topics`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
I tried but it adds after 6.
LOAD DATA INFILE 'list.txt' INTO TABLE topics
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\r\n' (other);
it added from 7, instead I wanted it to be from 1
Upvotes: 1
Views: 75
Reputation: 17665
Load data infile is the equivalent of an INSERT and is behaving as expected. There is no update option. I suggest you load to a staging table then UPDATE to target. I do foresee a problem though since there is no way of knowing which row to update in target.
Upvotes: 1