1

Como eu faço para múltiplas colunas de uma tabela referenciarem uma chave estrangeira de outra tabela? Eu quero que todas as colunas chamadas "SLOT", POSSAM armazenar uma chave da tabela mods. OBS: Estou usando a última versão do NETBEANS não sei se isso faz alguma diferença

create table "USE".UPGRADE
(
    U_ID INTEGER GENERATED ALWAYS AS IDENTITY not null,
    W_ID INTEGER,
    MODCAPACITY INTEGER,
    OROKINREACTOR BOOLEAN,
    LENS INTEGER,
    AURASLOT INTEGER,
    EXILUSSLOT INTEGER,
    POSTURESLOT INTEGER,
    SLOT1 INTEGER,
    SLOT2 INTEGER,
    SLOT3 INTEGER,
    SLOT4 INTEGER,
    SLOT5 INTEGER,
    SLOT6 INTEGER,
    SLOT7 INTEGER,
    SLOT8 INTEGER,
    SLOT9 INTEGER,
    SLOT10 INTEGER,
    primary key (U_ID),
    foreign key(W_ID) references WARFRAMES(W_ID)
);

create table "USE".MODS
(
    M_ID INTEGER GENERATED ALWAYS AS IDENTITY not null,
    U_ID INTEGER,
    NAME CHAR(30) not null unique,
    CAPACITYDRAIN INTEGER not null,
    POLARITY INTEGER not null,
    MODCOMPATIBILITY INTEGER not null,
    CONCLAVE INTEGER not null,
    QUANTITY INTEGER not null,
    RARITY INTEGER not null,
    MODLEVEL INTEGER not null,
    MODTYPE INTEGER not null,
    primary key(M_ID),
    foreign key(U_ID) references UPGRADE(U_ID)
);

3
  • A sintaxe acima não é do SQL Server; poderia confirmar qual é o sgbd?
    – José Dız
    1/03/2017 às 14:05
  • Faltou algum detalhe? Precisa de mais alguma informação para aceitar a resposta abaixo? 2/03/2017 às 14:05
  • Oi, obrigado pela ajuda, não sei dizer ao certo a linguagem SQL que eu estou usando eu simplesmente abri o netbeans e comecei a digitar os códigos que eu lembrava kkkk, mas os comandos que o Murillo Goulart me mandou funcionaram, mais uma vez obrigado pela ajuda e desculpe não responder mais cedo. 3/03/2017 às 16:10

1 Resposta 1

0

Segue abaixo o comando para as colunas 1 e 2 (as demais devem seguir a mesma lógica):

alter table "USE".UPGRADE
add constraint SLOT1_FK FOREIGN KEY ( SLOT1 ) references "USE".MODS(M_ID);
alter table "USE".UPGRADE
add constraint SLOT2_FK FOREIGN KEY ( SLOT2 ) references "USE".MODS(M_ID);

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .