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

  • Home
  • SEARCH
  • 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 8789727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:29:39+00:00 2026-06-13T22:29:39+00:00

I am trying to re define my database design adding some extra tables so

  • 0

I am trying to re define my database design adding some extra tables so There are no repeated names for example in my table Departaments and Jobs…

But I am getting the error 121 which has to do with foreign keys, can you explain why is this problem?

I am doing this in sqlfiddle

I am trying to do something like this but had no luck in sqlfiddle there is what i have working at the moment

 CREATE TABLE Employee(
          EmployeeID  INTEGER      NOT NULL PRIMARY KEY,
          Name        VARCHAR(30)  NOT NULL,
          Sex         CHAR(1)      NOT NULL,
          Address     VARCHAR(80)  NOT NULL,
          Security    VARCHAR(15)  NOT NULL          
        );

        CREATE TABLE Departments  (
            DeptID   INTEGER     NOT NULL PRIMARY KEY,
            DeptName VARCHAR(30) NOT NULL
        );

If I uncomment the code I get
Schema Creation Failed: Can’t create table ‘db_2_2bf4a.project-employee’ (errno: 121):

        CREATE TABLE `Dept-Employee`(
          EmployeeID   INTEGER NOT NULL,          
          DeptID       INTEGER NOT NULL,
          CONSTRAINT fk_DeptID     FOREIGN KEY (DeptID)  REFERENCES Departments(DeptID),
          CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
        );

       CREATE TABLE `Dept-Manager`(
          EmployeeID   INTEGER NOT NULL,          
          DeptID       INTEGER NOT NULL,
          CONSTRAINT fk_DeptID     FOREIGN KEY (DeptID)  REFERENCES Departments(DeptID),
          CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
        );

        CREATE TABLE Jobs (
            JobID            INTEGER      NOT NULL PRIMARY KEY,
            JobName          VARCHAR(30)  NOT NULL,
            JobSalary        DOUBLE(15,3) NOT NULL default '0.000', 
            JobSalaryperDay  DOUBLE(15,3) NOT NULL default '0.000', 
            DeptID           INTEGER      NOT NULL
        );

        CREATE TABLE `Jobs-Employee`(
          EmployeeID   INTEGER NOT NULL,
          JobID        INTEGER NOT NULL,
          CONSTRAINT fk_JobID      FOREIGN KEY (JobID)      REFERENCES Jobs(JobID),
          CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
        );

        CREATE TABLE Project(
          ProjectID    INTEGER NOT NULL PRIMARY KEY,
          ProjectDesc   VARCHAR(200) NOT NULL,
          StartDate     DATE NOT NULL,
          EndDate       DATE NOT NULL, 
          DaysOfWork    INTEGER NOT NULL,
          NoEmployees   INTEGER NOT NULL,
          EstimatedCost DOUBLE(15,3) NOT NULL default '0.000', 
          RealCost      DOUBLE(15,3) NOT NULL default '0.000' 
        );


        CREATE TABLE `Project-Employee`(
          ProjectID    INTEGER NOT NULL,
          EmployeeID   INTEGER NOT NULL,
          Note         VARCHAR(200),
          DaysWork     INTEGER NOT NULL,
          CONSTRAINT fk_ProjectID  FOREIGN KEY (ProjectID)  REFERENCES Project(ProjectID),
          CONSTRAINT fk_EmployeeID FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
        );

So after I do not know if this queries would be correct

INSERT INTO `Departments` VALUES (1, 'Outsourcing');
    INSERT INTO `Departments` VALUES (2, 'Technician');
    INSERT INTO `Departments` VALUES (3, 'Administrative');

    INSERT INTO `Jobs` VALUES (1, 'welder'    ,500.550,16.7 ,2);
    INSERT INTO `Jobs` VALUES (2, 'turner'    ,500.100,16.67,2);
    INSERT INTO `Jobs` VALUES (3, 'assistant' ,650.100,21.67,2);
    INSERT INTO `Jobs` VALUES (4, 'supervisor',800.909,26.70,3);
    INSERT INTO `Jobs` VALUES (5, 'manager'   ,920.345,30.68,3);
    INSERT INTO `Jobs` VALUES (6, 'counter'   ,520.324,17.35,1);

    INSERT INTO `Dept-Employee` (10,1);
    INSERT INTO `Dept-Employee` (10,2);
    INSERT INTO `Dept-Employee` (10,3);
    INSERT INTO `Dept-Employee` (10,1);
    INSERT INTO `Dept-Employee` (10,3);

    INSERT INTO `Jobs-Employee` (10,3);
    INSERT INTO `Jobs-Employee` (10,3);
    INSERT INTO `Jobs-Employee` (10,4);
    INSERT INTO `Jobs-Employee` (10,6);
    INSERT INTO `Jobs-Employee` (10,5);

    INSERT INTO `Employee` VALUES (10, 'Joe',  'M', 'Anywhere', '927318344');
    INSERT INTO `Employee` VALUES (20, 'Moe',  'M', 'Anywhere', '827318322');
    INSERT INTO `Employee` VALUES (30, 'Jack', 'M', 'Anywhere', '927418343');
    INSERT INTO `Employee` VALUES (40, 'Marge','F', 'Evererre', '127347645');
    INSERT INTO `Employee` VALUES (50, 'Greg' ,'M', 'Portland', '134547633');


    INSERT INTO `Project` VALUES (1, 'The very first', '2008-7-04' , '2008-7-24' , 20, 5, 3000.50, 2500.00);
    INSERT INTO `Project` VALUES (2, 'Second one pro', '2008-8-01' , '2008-8-30' , 30, 5, 6000.40, 6100.40);


    INSERT INTO `Project-Employee` VALUES (1, 10, 'Worked all days'    , 20);
    INSERT INTO `Project-Employee` VALUES (1, 20, 'Worked just in defs', 11);
    INSERT INTO `Project-Employee` VALUES (1, 30, 'Worked just in defs', 17);
    INSERT INTO `Project-Employee` VALUES (1, 40, 'Contability '       , 8);
    INSERT INTO `Project-Employee` VALUES (1, 50, 'Managed the project', 8);
  • 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-13T22:29:41+00:00Added an answer on June 13, 2026 at 10:29 pm

    The reason is because the CONSTRAINT name you have provided already exist. Try changing the constraint name.

    for instance fk_EmployeeID on Dept-Manager already existed on Dept-Employee

    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to define three database tables - USERNAME, USER_SESSIONS, and TOOLBOX_DIRS_REGISTERED. I
I am trying to define a table structure/schema for this simulation database. I have
I'm trying to figure out how to define the schema of a database on
I'm trying to fix a design flaw that I recently ran across in some
I'm trying to define a field that's not in my database. Its form is
I'm trying to use a stored procedure to query some data from my database,
I am trying to define a one-to-many relationship between my two table in Entity
Im trying to define a select tag in my view. My view looks like
I'm trying to define a method in my vb.net interface that will only accept
I am trying to define a dynamic var in a different namespace. The Lobos

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.