MySQL Forums
Forum List  »  Spanish

Re: HACER INSERT Y UPDATE CON LOAD DATA LOCAL INFILE
Posted by: juan torre
Date: October 26, 2012 11:21AM

Buen día Jesús disculpe por lo de amiga, fue un error, mire le pongo este script para ver si puede ayudarme, este es un ejemplo sencillo que no estoy aplicando en ningún proyecto, solo es para darme a entender, saludos.

------

DROP database IF exists BDuno;
create database BDuno;

DROP database IF exists BDdos;
create database BDdos;

USE BDuno;
DROP TABLE IF exists empleado;
CREATE TABLE IF NOT EXISTS `empleado` (
`idEmp` int(11) NOT NULL AUTO_INCREMENT,
`nombre` varchar(50) NOT NULL,
`telefono` varchar(50) NOT NULL,
PRIMARY KEY (`idEmp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


INSERT INTO `empleado` (`idEmp`, `nombre`, `telefono`) VALUES
(1, 'ROMAN', '4666666'),
(2, 'JUAN', '4155678'),
(3, 'joel', '4542213'),
(4, 'manuel', '4567787'),
(5, 'Alejandro', '4321112'),
(6, 'RAMON', '4345255'),
(7, 'TERESA', '4554411');


DROP TABLE IF exists sucursal;
CREATE TABLE IF NOT EXISTS `sucursal` (
`idSucursal` int(11) NOT NULL AUTO_INCREMENT,
`idEmp` int(11) NOT NULL,
`nombre` varchar(50) NOT NULL,
`telefono` varchar(50) NOT NULL,
PRIMARY KEY (`idSucursal`),
KEY `idEmp` (`idEmp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


INSERT INTO `sucursal` (`idSucursal`, `idEmp`, `nombre`, `telefono`) VALUES
(1, 2, 'wallmart', '4556677'),
(2, 1, 'soriana', '4112233'),
(3, 2, 'plaza del sol', '4556533');


ALTER TABLE `sucursal`
ADD CONSTRAINT `sucursal_ibfk_2` FOREIGN KEY (`idEmp`) REFERENCES `empleado` (`idEmp`) ON UPDATE CASCADE;



use BDdos;

DROP TABLE IF exists empleado;
CREATE TABLE IF NOT EXISTS `empleado` (
`idEmp` int(11) NOT NULL AUTO_INCREMENT,
`nombre` varchar(50) NOT NULL,
`telefono` varchar(50) NOT NULL,
PRIMARY KEY (`idEmp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


INSERT INTO `empleado` (`idEmp`, `nombre`, `telefono`) VALUES
(1, 'roman', '4454345'),
(2, 'juan', '4155678'),
(3, 'joel', '4542213'),
(4, 'manuel', '4567787'),
(5, 'Alejandro', '4321112');


DROP TABLE IF exists sucursal;
CREATE TABLE IF NOT EXISTS `sucursal` (
`idSucursal` int(11) NOT NULL AUTO_INCREMENT,
`idEmp` int(11) NOT NULL,
`nombre` varchar(50) NOT NULL,
`telefono` varchar(50) NOT NULL,
PRIMARY KEY (`idSucursal`),
KEY `idEmp` (`idEmp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


INSERT INTO `sucursal` (`idSucursal`, `idEmp`, `nombre`, `telefono`) VALUES
(1, 2, 'wallmart', '4556677'),
(2, 1, 'soriana', '4112233'),
(3, 2, 'plaza del sol', '4556533');

ALTER TABLE `sucursal`
ADD CONSTRAINT `sucursal_ibfk_2` FOREIGN KEY (`idEmp`) REFERENCES `empleado` (`idEmp`) ON UPDATE CASCADE;


-- AHORA QUIERO ACTUALIZAR HE INSERTAR LOS DATOS DE LAS COLUMNAS NOMBRE Y TELEFONO DE LA TABLA EMPLEADO DE LA BASE DE DATOS BDuno A LA TABLA EMPLEADO DE LA BASE DE DATOS BDdos

use BDuno;
SELECT * INTO OUTFILE 'c:/pruebass/prueba.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '#' LINES TERMINATED BY '\r\n' FROM empleado;

use BDdos;
LOAD DATA LOCAL infile 'c:/pruebass/prueba.csv' replace into table empleado fields terminated by ','
optionally enclosed by '#' lines terminated by '\r\n';

------

y me marca el error Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`bddos`.`sucursal`, CONSTRAINT `sucursal_ibfk_2` FOREIGN KEY (`idEmp`) REFERENCES `empleado` (`idEmp`) ON UPDATE CASCADE)

saludos

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: HACER INSERT Y UPDATE CON LOAD DATA LOCAL INFILE
1478
October 26, 2012 11:21AM


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.