error when creating relationships in mysql

1

when updating the data id_estado in the table tb_extintores all the data are updated in the column id state of tb_register_bloqueo_extintor

should only update the id_state of a single code not all.

I do not know if the relationship is badly created

    tb_extintores   CREATE TABLE 'tb_extintores' (
     'id_extintor' int(30) NOT NULL,
     'rut_cliente' varchar(20) DEFAULT NULL,
     'fecha_recarga' date DEFAULT NULL,
     'fecha_vencimiento' date DEFAULT NULL,
     'id_kilo' int(10) NOT NULL,
     'id_tipo' int(10) NOT NULL,
     'id_estado' int(10) NOT NULL,
     'id_asignado' int(10) NOT NULL,
     PRIMARY KEY ('id_extintor'),
     KEY 'id_estado' ('id_estado'),
     KEY 'id_tipo' ('id_tipo'),
     KEY 'id_kilo' ('id_kilo'),
     KEY 'rut_cliente' ('rut_cliente'),
     KEY 'rut_cliente_2' ('rut_cliente'),
     KEY 'rut_cliente_3' ('rut_cliente'),
     KEY 'id_asignado' ('id_asignado'),
     CONSTRAINT 'tb_extintores_ibfk_1' FOREIGN KEY ('id_estado') REFERENCES 'tb_estado' ('id_estado') ON DELETE NO ACTION,
     CONSTRAINT 'tb_extintores_ibfk_2' FOREIGN KEY ('id_tipo') REFERENCES 'tb_tipo_extintor' ('id_tipo') ON DELETE NO ACTION ON UPDATE CASCADE,
     CONSTRAINT 'tb_extintores_ibfk_3' FOREIGN KEY ('id_kilo') REFERENCES 'tb_kilos_extintor' ('id_kilo') ON DELETE NO ACTION ON UPDATE CASCADE,
     CONSTRAINT 'tb_extintores_ibfk_4' FOREIGN KEY ('id_asignado') REFERENCES 'tb_extintor_asignado' ('id_asignado')
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1



tb_registro_bloqueo_extintor    CREATE TABLE 'tb_registro_bloqueo_extintor' (
 'codigo' int(30) NOT NULL,
 'id_motivo' int(10) NOT NULL,
 'id_estado' int(10) NOT NULL,
 PRIMARY KEY ('codigo'),
 KEY 'id_motivo' ('id_motivo'),
 KEY 'id_estado' ('id_estado'),
 KEY 'codigo' ('codigo'),
 KEY 'id_estado_2' ('id_estado'),
 CONSTRAINT 'tb_registro_bloqueo_extintor_ibfk_2' FOREIGN KEY ('id_motivo') REFERENCES 'tb_motivo_bloqueo_extintor' ('id_motivo') ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT 'tb_registro_bloqueo_extintor_ibfk_3' FOREIGN KEY ('codigo') REFERENCES 'tb_extintores' ('id_extintor') ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT 'tb_registro_bloqueo_extintor_ibfk_4' FOREIGN KEY ('id_estado') REFERENCES 'tb_extintores' ('id_estado') ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
    
asked by sebastian bizama inostroza 27.10.2017 в 00:07
source

1 answer

1

You must first establish the parameter to update id_estado = 2 which is the change you want to make, when referring to a table sweep, I mean that if you do not define where tb_extintores.id_extintor = 1, then what you will do is that to all the fields of the table tb_extintores you will set them id_estado = 2, like this or do you want a better explanation?

UPDATE tb_extintores SET id_estado = 2 WHERE tb_extintores.id_extintor = 1;
    
answered by 29.10.2017 / 04:10
source