Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:52:38+00:00 2026-06-13T21:52:38+00:00

I’m trying to setup a MySQL-Script that creates 5 tables. In three tables, there

  • 0

I’m trying to setup a MySQL-Script that creates 5 tables. In three tables, there is a FOREIGN KEY, and for all three of them the same error appears:

Error Code: 1072. Key column ... doesn't exist in table

whereas … are Gebaeude, Dept_Name and Mat_Nr

Here’s the script

use cs261_24;

drop table if exists Professor;
drop table if exists Departement;
drop table if exists Gebaeude;
drop table if exists Student;
drop table if exists Pruefung;


CREATE TABLE Gebaeude (
                        Gebaeude    VARCHAR(20) NOT NULL PRIMARY KEY,
                        Hauswart    VARCHAR(20) NOT NULL,
                        Adresse     VARCHAR(20) NOT NULL
)engine = innodb;

CREATE TABLE Professor  (
                        P_ID        INTEGER PRIMARY KEY CHECK (P_ID > 0),
                        P_Name      VARCHAR(20) NOT NULL,
                        Dept_Name   VARCHAR(20) NOT NULL,
                        Raum        INTEGER UNIQUE CHECK (Raum > 0),
                        Tel         INTEGER(10) UNIQUE CHECK (Tel > 210000000),
                        FOREIGN KEY (Gebaeude) REFERENCES Gebaeude (Gebaeude) 
)engine = innodb;

CREATE TABLE Departement (
                        Dept_Name   VARCHAR(20) NOT NULL PRIMARY KEY,
                        Vorsteher   VARCHAR(20) NOT NULL
)engine = innodb;

CREATE TABLE Student (
                        Mat_Nr      INTEGER(8) PRIMARY KEY CHECK (Mat_Nr > 0),
                        S_Name      VARCHAR(20) NOT NULL,
                        Semester    INTEGER CHECK(Semester > 0),
                        FOREIGN KEY (Dept_Name) REFERENCES Departement (Dept_Name) 
)engine = innodb;

CREATE TABLE Pruefung (
                        Pr_ID       INTEGER PRIMARY KEY CHECK(Pr_ID > 0),
                        Fach        VARCHAR(20) NOT NULL,
                        Pruefer     VARCHAR(20) NOT NULL,
                        Note        FLOAT CHECK (Note >= 1 AND Note <= 6),
                        FOREIGN KEY (Mat_Nr) REFERENCES Student (Mat_Nr)
)engine = innodb;

Why? I work with MySQL Workbench, and I clearly see the created tables, plus the specific columns are marked as primary keys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:52:39+00:00Added an answer on June 13, 2026 at 9:52 pm

    You are doing it wrong, take a look to this example

    http://www.sqlfiddle.com/#!2/a86cf

    your FK line should be more like this:

    FOREIGN KEY (field_that_will_be_Fk) REFERENCES Table_to_reference (field_to_reference)

    I.E=

    CREATE TABLE Gebaeude (
                            Gebaeude    VARCHAR(20) NOT NULL PRIMARY KEY,
                            Hauswart    VARCHAR(20) NOT NULL,
                            Adresse     VARCHAR(20) NOT NULL
    )engine = innodb;
    
    CREATE TABLE Professor  (
                           Gebaeude_FK varchar(20) NOT NULL,
                            P_ID        INTEGER PRIMARY KEY CHECK (P_ID > 0), 
                            P_Name      VARCHAR(20) NOT NULL,
                            Dept_Name   VARCHAR(20) NOT NULL,
                            Raum        INTEGER UNIQUE CHECK (Raum > 0),
                            Tel         INTEGER(10) UNIQUE CHECK (Tel > 210000000),
                            FOREIGN KEY (Gebaeude_FK) REFERENCES Gebaeude (Gebaeude) 
    )engine = innodb;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.