How to make a relationship with dependence of two tables in mysql?

0

Good morning, I have the doubt of how to make a relationship of two tables where: the column n_employed of the table entry_register can not be filled without that same data (number of identical worker) existing previously in the record table. that for security reasons since I'm creating a registration system in theory to register my workers, and when they check your entry and exit know that they are already registered and if not, send conditional in PHP

    
asked by J. wink 30.05.2016 в 04:56
source

1 answer

2

I recommend creating a foreign key, like this:

CREATE TABLE registro (
    n_empleado INT PRIMARY KEY AUTO_INCREMENT,
    /* resto de campos de la tabla */
);

CREATE TABLE entrada_salidas (
    registro INT PRIMARY KEY AUTO_INCREMENT,
    n_empleado INT NOT NULL,
    /* resto de campos */
    FOREIGN KEY (n_empleado) REFERENCES registro(n_empleado)
);
    
answered by 30.05.2016 в 16:43