Monday 3 September 2018

MySQL creates an array with the set attribute of another table?

I am a beginner at this but is it possible (in MySQL workbench) to create an attribute that is a set depended on an attribute from another table?

CREATE TABLE danes (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    nationality VARCHAR(20),
    gender CHAR(1),
    degree SET ?????????????????? from degree(level)
);

CREATE TABLE degree (
    level VARCHAR(10),
    subject VARCHAR(20),
    institutionawarding VARCHAR(20),
    yearawarded DATE,
    PRIMARY KEY (level, subject)
);

never mind I got it

I am guessing that you want another table, a junction table:
CREATE TABLE DaneDegrees (
    DanesId INT REFERENCES danes(id),
    Level VARCHAR(10),
    Subject VARCHAR(20),
    FOREIGN KEY fk_level_subject(level, subject) REFERENCES Degree(level, Subject)
);

I would, however, have an INT AUTO_INCREMENT PRIMARY KEY in both Danes and Degrees.

0 comments:

Post a Comment