I need to perform a validation where I can only enter the registration of a race in the database if the id
of the driver and the user are present in their respective banks.
What is the best algorithm to handle this situation?
Follow the database tables:
CREATE TABLE 'corridas' (
'id_corrida' int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
'm_id' int(11) NOT NULL,
'p_id' int(11) NOT NULL,
'c_valor' int(9) NOT NULL,
PRIMARY KEY ('id_corrida'),
KEY 'fk_motorista' ('m_id'),
KEY 'fk_passageiros' ('p_id')
);
CREATE TABLE 'motorista' (
'm_id' int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
'm_nome' varchar(255) NOT NULL,
'm_nasc' datetime NOT NULL,
'm_cpf' int(11) NOT NULL,
'm_modeloCarro' varchar(255) DEFAULT NULL,
'm_sexo' char(1) DEFAULT NULL,
'm_status' char(1) DEFAULT NULL,
PRIMARY KEY ('m_id')
);
CREATE TABLE 'passageiro' (
'p_id' int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
'p_nome' varchar(255) NOT NULL,
'p_nasc' datetime NOT NULL,
'p_cpf' int(11) NOT NULL,
'p_sexo' char(1) DEFAULT NULL,
PRIMARY KEY ('p_id')
);