Is it possible to use two identical id's in the same table?

0

I have a situation that I need to ask a question. I have a table as below:

CREATE TABLE confrontos(  
    id_confrontos INT AUTO_INCREMENT NOT NULL,
    dt_confronto DATE NOT NULL,
    id_estadios INT NOT NULL,
    ***id_clubes*** INT NOT NULL,
    ***id_clubes*** INT NOT NULL,
    id_treinadores INT NOT NULL,
    escore1 INT NOT NULL,
    escore2 INT NOT NULL,
    CONSTRAINT PK_confrontos PRIMARY KEY(id_confrontos),
    CONSTRAINT FK_confrontos_estadios foreign key (id_estadios)   
        REFERENCES estadios (id_estadios),
    CONSTRAINT FK_confrontos_clubes foreign key (id_clubes)
        REFERENCES clubes (id_clubes),
    CONSTRAINT FK_confrontos_treinadores foreign key (id_treinadores)
        REFERENCES treinadores (id_treinadores)
);

I've already seen that MySql does not allow you to create this table for duplicity in the id_clubes field. What would be the best way to create this table?

    
asked by anonymous 24.10.2018 / 16:30

1 answer

0

You need to create an auxiliary table between clashes and times, example timeswitch table in it will have the id of the clash and the id of the team, how it will work

controntoid 1 time 1

controntoid 1 time 2

and in the confroto table you reference this table

CREATE TABLE timesquevaojogar(  
    id_Timesquevaojogar
    id_confrontos
    id_clubes 

If you want to search more about it, search for n para n

    
24.10.2018 / 16:44