0

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

4
  • Are you talking about a foreign key? Commented Sep 28, 2014 at 16:43
  • I'm unsure what you're trying to achieve. Which degree's level should show up on an individual "danes" when there is no link between them? Or are you asking how to link them? Commented Sep 28, 2014 at 16:50
  • +1 to @GordonLinoff's answer, but the reason this doesn't work is that it would require new values in degree.level to alter the definition of the SET. What happens when there are more than 64 distinct values of level? (The MySQL SET data type is limited to 64 elements.) Commented Sep 28, 2014 at 17:14
  • well baiscly I want to create the attribute but I dont know how the SET type works if it can be use like linking the attibute to level of the table degrees or I acually have to create a new one i don't know Commented Sep 28, 2014 at 18:39

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

apparently you cant just say

<attribute_name> set(get set from another tabe)

the set thing doesn't work that way

eventhough you can apparently update it so it actually can

update table_name

attribute = (select * from another table_name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.