Mysql
 sql >> Database >  >> RDS >> Mysql

Importa CSV per aggiornare solo una colonna nella tabella

Puoi utilizzare LOAD DATA INFILE per caricare in blocco le 800.000 righe di dati in una tabella temporanea, quindi utilizzare più tabelle UPDATE sintassi per unire la tua tabella esistente alla tabella temporanea e aggiornare i valori delle quantità.

Ad esempio:

CREATE TEMPORARY TABLE your_temp_table LIKE your_table;

LOAD DATA INFILE '/tmp/your_file.csv'
INTO TABLE your_temp_table
FIELDS TERMINATED BY ','
(id, product, sku, department, quantity); 

UPDATE your_table
INNER JOIN your_temp_table on your_temp_table.id = your_table.id
SET your_table.quantity = your_temp_table.quantity;

DROP TEMPORARY TABLE your_temp_table;