How do I get multiple columns of a table to reference a foreign key from another table?

Asked

Viewed 81 times

1

How do I get multiple columns of a table to reference a foreign key from another table? I want all columns called "SLOT", CAN store a key from the mods table. NOTE: I’m using the latest version of NETBEANS I don’t know if it makes any difference

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)
);

  • The above syntax is not SQL Server; could confirm which is sgbd?

  • Missing any details? Need some more information to accept the answer below?

  • Hi, thanks for the help, I can’t say for sure the SQL language I’m using I just opened netbeans and started typing the codes I remembered kkkk, but the commands that Murillo Goulart sent me worked, thanks again for the help and sorry I didn’t respond earlier.

1 answer

0


Below is the command for columns 1 and 2 (the others must follow the same logic):

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.