sqlrelationshipsqlyog

how to make a relationship table between two table? SQL


Im new to SQL and Im trying to make a relationship table for Graduate Students and Projects. Project is worked on by graduate students known as the project’s research assistants. My problem is that I got an Error Code: 1064, How to fix that? I cant identify the problem.

CREATE TABLE Professor(
Prof_SSN VARCHAR(12),
Prof_Name VARCHAR(12),
Prof_Age VARCHAR(3),
`Rank` VARCHAR(12),
`Research Specialty` VARCHAR(12),
PRIMARY KEY (Prof_SSN)
);

CREATE TABLE `Graduate Students`(
Std_SSN VARCHAR(12),
Std_Name VARCHAR(12),
Std_Age VARCHAR(3),
Degree VARCHAR(12),
PRIMARY KEY (Std_SSN)
);

CREATE TABLE Projects(
`Project number` VARCHAR(10),
`Starting date` VARCHAR(12),
Deadline VARCHAR(8),
Sponsor VARCHAR(12),
Budget VARCHAR(12),
PRIMARY KEY (`Project number`)
);

CREATE TABLE `Project’s Research Assistants`(
Std_SSN VARCHAR(12),
`Project number` VARCHAR(10),
PRIMARY KEY (`Project number`)
FOREIGN KEY (Std_SSN) REFERENCES `Graduate Students`
);```

Solution

  • The last table creation should be:

    CREATE TABLE `Project’s Research Assistants` (
      Std_SSN VARCHAR(12),
      `Project number` VARCHAR(10),
      PRIMARY KEY (`Project number`)
      FOREIGN KEY (Std_SSN) REFERENCES `Graduate Students` (Std_SSN) -- fixed here
    );