K
If you create the tables this way:Adding to FOREIGN KEY sponsor in table TIMES, you start to have a relationship UM-PARA-UM with sponsor, that is, each team will have a sponsor.CREATE TABLE times+time1+time2+time3+time4 (
nome Text,
id int PRIMARY KEY,
f1 Text,
f2 Text,
f3 Text,
f4 Text,
ID_PATROCINADOR int NOT NULL,
CONSTRAINT PK_TIMES FOREIGN KEY (ID_PATROCINADOR) REFERENCES patrocinador (id)
)
If you need to know, which TIME the PATROCINADORis sponsoring, it will be necessary by one FOREIGN KEYin sponsor also, which will be a relationship UM-PARA-MUITOS, that is, a sponsor may sponsor many teams.CREATE TABLE patrocinador (
nome Text,
valor Text,
cnpj int PRIMARY KEY,
id Text,
id Text,
FOREIGN KEY( id) REFERENCES times+ time1+time2+time3+time4 (id)
)
CREATE TABLE jogador (
cpf int PRIMARY KEY,
sobrenome Text,
nome Text,
lider Text,
time Text,
id int,
FOREIGN KEY( id) REFERENCES times+ time1+time2+time3+time4 (id)
)
I'd like to give you some tips on how to create the TABELAS:When creating the table names, try by the entity name in the
plural, for example: TIMES, PATROCINADORES, JOGADORES, etc.When it comes to creating CONSTRAINTS try by their name to get easy to find when you give some problem, for example:CREATE TABLE patrocinador (
nome Text,
valor Text,
cnpj int ,
id Text,
id Text,
CONSTRAINT PK_JOGADORES FOREIGN KEY (cnpj),
CONSTRAINT FK_PATROCINADOR_TIMES FOREIGN KEY( id) REFERENCES times+ time1+time2+time3+time4 (id)
)
CREATE TABLE jogador (
cpf int,
sobrenome Text,
nome Text,
lider Text,
time Text,
id int,
insira o código aqui
CONSTRAINT PK_JOGADORES PRIMARY KEY (ID),
CONSTRAINT FK_JOGADORES_TIMES FOREIGN KEY( id) REFERENCES times+ time1+time2+time3+time4 (id)
)
Create CONSTRAINT's giving their names makes it easy to solve future mistakes.