1
I need to perform a validation where I can only enter the registration of a race in the database if the id
driver and user are present in their respective seats.
What is the best algorithm to deal with this situation?
Follow the tables of the bank:
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`)
);
Are you working with PHP? Wouldn’t be the ids in their respective tables?
– Diego Vieira
I’m using php but as I’m studying I’ve never done anything like this
– J.Rodrigues
Edit your question and place the tables in the bank.
– Diego Vieira