MySQL Forums
Forum List  »  Spanish

Re: HACER INSERT Y UPDATE CON LOAD DATA LOCAL INFILE
Posted by: Jesus Uzcanga
Date: October 25, 2012 09:15AM

Hola Juan

Específicamente un UPDATE no se puede hacer, sin embargo, puedes lograr que la tabla que la tabla actualice los datos ya existentes para evitar duplicidad y que los nuevos si los inserte. Para este deberás utilizar la sentencia "REPLACE". Ejemplo para LINUX:


LOAD DATA INFILE '/ruta/ruta2/archivo.txt' REPLACE INTO TABLE TABLA1;

Donde archivo.txt es el csv y TABLA1 es la tabla en la que insertas los datos.

Esta sentencia reemplaza datos existentes según el o los KEY de la tabla.

Es decir que para una tabla

campo_key | campo_1 | campo2 | campo3

Con que solo el campo_key se encuentre repetido el hará el replace del registro


Espero que te sirva!!!

___________________________
Ing. Jesús Alfredo Uzcanga
Twitter: @JesusUzcanga

We learn the 20% of what we HEAR,
the 50% of what we SEE,
the 80% of what we DO and
the 95% of what we TEACH.

____________________________________________________________
https://www.linkedin.com/in/jauzcanga/

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: HACER INSERT Y UPDATE CON LOAD DATA LOCAL INFILE
6442
October 25, 2012 09:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.