-1
I am doing a database course and we have made a database with several tables with Foreign key below. I would like to know how to enter the data correctly in this table, because when inserting the car as I would insert the brand if I still do not have it registered. The teacher said the strongest table is the car table so he recommended to start inserting by it.
CREATE DATABASE PROJETO;
USE PROJETO;
CREATE TABLE CLIENTE(
IDCLIENTE INT PRIMARY KEY AUTO_INCREMENT,
NOME VARCHAR(30) NOT NULL,
SEXO ENUM('M','F') NOT NULL,
ID_CARRO INT UNIQUE
);
CREATE TABLE TELEFONE(
IDTELEFONE INT PRIMARY KEY AUTO_INCREMENT,
NUMERO VARCHAR(30) NOT NULL,
TIPO ENUM('CEL','RES','COM') NOT NULL,
ID_CARRO INT UNIQUE
);
CREATE TABLE MARCA(
IDMARCA INT PRIMARY KEY AUTO_INCREMENT,
MARCA VARCHAR(30) UNIQUE
);
CREATE TABLE CARRO(
IDCARRO INT PRIMARY KEY AUTO_INCREMENT,
MODELO VARCHAR(30) NOT NULL,
PLACA VARCHAR(10) NOT NULL UNIQUE,
ID_MARCAR INT UNIQUE
);
CREATE TABLE COR(
IDCOR INT PRIMARY KEY AUTO_INCREMENT,
COR VARCHAR(30) UNIQUE
);
CREATE TABLE CARRO_COR(
ID_CARRO INT,
ID_COR INT,
PRIMARY KEY (ID_CARRO,ID_COR)
);
/* CONSTRAINTS */
ALTER TABLE TELEFONE
ADD CONSTRAINT FK_TELEFONE_CLIENTE
FOREIGN KEY(ID_CLIENTE)
REFERENCES CLIENTE(IDCLIENTE);
ALTER TABLE CLIENTE
ADD CONSTRAINT FK_CLIENTE_CARRO
FOREIGN KEY(ID_CARRO)
REFERENCES CARRO(IDCARRO);
ALTER TABLE CARRO
ADD CONSTRAINT FK_CARRO_MARCA
FOREIGN KEY(ID_MARCAR)
REFERENCES MARCA(IDMARCA);
ALTER TABLE CARRO_COR
ADD CONSTRAINT FK_COR
FOREIGN KEY(ID_COR)
REFERENCES COR(IDCOR);
ALTER TABLE CARRO_COR
ADD CONSTRAINT FK_CARRO
FOREIGN KEY(ID_CARRO)
REFERENCES CARRO(IDCARRO);
INSERT INTO CARRO VALUES(NULL,'POLO 1.6','GVO-1015',1)
INSERT INTO CARRO VALUES(NULL,'PRISMA 1.4','HCQ-4059',4)
INSERT INTO CARRO VALUES(NULL,'STRADA 1.4','OWN-1312',2)
INSERT INTO CARRO VALUES(NULL,'GRAND SIENA','GQC-1052',2)
INSERT INTO CARRO VALUES(NULL,'SAVEIRO 1.6','UWN-8963',1)
INSERT INTO CARRO VALUES(NULL,'COROLLA 2.0','DAN-0608',4)
INSERT INTO CARRO VALUES(NULL,'COROLLA XEI','BRE-8974',4)
INSERT INTO CARRO VALUES(NULL,'POLO SEDAN 1.6','ANA-1010',1)
INSERT INTO CARRO VALUES(NULL,'FIAT UNO WAY','DAI-5565',2)
INSERT INTO CARRO VALUES(NULL,'HILUX DIESEL','OWM-8956',4)
INSERT INTO CLIENTE VALUES(NULL,'DANIEL','M',2)
INSERT INTO CLIENTE VALUES(NULL,'HERALDO','M',3)
INSERT INTO CLIENTE VALUES(NULL,'BRENO','M',4)
INSERT INTO CLIENTE VALUES(NULL,'PEDRO','M',5)
INSERT INTO CLIENTE VALUES(NULL,'GERALDO','M',6)
INSERT INTO CLIENTE VALUES(NULL,'MAURA','F',7)
INSERT INTO CLIENTE VALUES(NULL,'DAIANE','F',8)
INSERT INTO CLIENTE VALUES(NULL,'MARCUS','M',9)
INSERT INTO CLIENTE VALUES(NULL,'DIOVANI','M',10)
INSERT INTO CLIENTE VALUES(NULL,'SAMIRA','F',11)
INSERT INTO MARCA VALUES(NULL,'VOLKSWAGEN')
INSERT INTO MARCA VALUES(NULL,'FIAT')
INSERT INTO MARCA VALUES(NULL,'CHEVROLET')
INSERT INTO MARCA VALUES(NULL,'TOYOTA')
INSERT INTO COR VALUES(NULL,'AMARELO')
INSERT INTO COR VALUES(NULL,'AZUL')
INSERT INTO COR VALUES(NULL,'BRANCO')
INSERT INTO COR VALUES(NULL,'LARANJA')
INSERT INTO COR VALUES(NULL,'VERMELHO')
INSERT INTO COR VALUES(NULL,'ROSA')
INSERT INTO COR VALUES(NULL,'DOURADO')
INSERT INTO COR VALUES(NULL,'VERDE')
INSERT INTO COR VALUES(NULL,'PRATA')
INSERT INTO TELEFONE VALUES(NULL,'3331-3734','CEL',2)
INSERT INTO TELEFONE VALUES(NULL,'3331-3123','COM',3)
INSERT INTO TELEFONE VALUES(NULL,'3331-1232','RES',4)
INSERT INTO TELEFONE VALUES(NULL,'3331-4566','COM',5)
INSERT INTO TELEFONE VALUES(NULL,'3331-7567','RES',6)
INSERT INTO TELEFONE VALUES(NULL,'3331-4356','COM',7);