Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/04/2013, 10:38
ichristh
 
Fecha de Ingreso: marzo-2013
Ubicación: México
Mensajes: 5
Antigüedad: 11 años, 2 meses
Puntos: 0
Respuesta: No puedo ingresar registros.

Definí las tablas con PK, posteriormente alteré todas y establecí las FK, de ahí empecé a tener problemas, puesto que no podía ingresar ningún registro. Y me dice: Error Code: 1452 Cannod add or update a child row a foreing key constraint fails.

Mi base de datos es la siguiente.

Código MySQL:
Ver original
  1. create database empresa;
  2. use empresa;
  3. create table Oficinas(
  4.     Oficina int(2) primary key,
  5.     Ciudad varchar(10),
  6.     Región varchar(6),
  7.     Dir int(3),
  8.     Objetivo int(9),
  9.     Ventas int(9)
  10. );
  11.  
  12. create table Clientes(
  13.     Num_clie int(4) primary key,
  14.     Empresa varchar(20),
  15.     Rep_clie int(3),
  16.     Lím_crédito int(8)
  17. );
  18.  
  19. create table Repventas(
  20.     Num_empl int(3) primary key,
  21.     Nombre varchar(20),
  22.     Edad int(2),
  23.     Oficina_Rep int(2),
  24.     Título varchar(15),
  25.     Contrato date not null,
  26.     Director int(3),
  27.     Cuotra int(10),
  28.     Ventas float(9)
  29. );
  30.  
  31. create table Pedidos(
  32.     Núm_pedido int(6),
  33.     Fecha_pedido date not null,
  34.     Clie int(4),
  35.     Rep int(3),
  36.     Fab varchar(3),
  37.     Producto varchar(6),
  38.     Cant int(2),
  39.     Importe int(7)
  40. );
  41.  
  42. create table Productos(
  43.     Id_fábrica int(3),
  44.     Id_producto int(6),
  45.     Descripción varchar(20),
  46.     Precio int(6),
  47.     Existencia int(3),
  48.     primary key(Id_fábrica,Id_producto)
  49. );
  50.  
  51.  
  52. alter table Oficinas
  53. add foreign key(Dir) references Repventas(Num_empl);
  54. alter table Repventas
  55. add foreign key(Director) references Repventas(Num_empl);
  56. alter table Pedidos
  57. add foreign key(Fab,Producto) references Productos(Id_fábrica,Id_producto);
  58. alter table Clientes
  59. add foreign key(Rep_clie) references Repventas(Num_empl);