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 9089797
In Process

The Archive Base Latest Questions

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

I have an assignment (so answer accordingly) which includes a many-to-many relationship between Animals

  • 0

I have an assignment (so answer accordingly) which includes a many-to-many relationship between Animals and Zookeepers and I’ve set my SQL to create this relationship as the following:

CREATE TABLE Animal
( 
    animalID VARCHAR(5) NOT NULL PRIMARY KEY,
    -- more rows created here;
);

CREATE TABLE Zookeeper 
( 
    employeeID VARCHAR(5) NOT NULL PRIMARY KEY,
    -- more rows created here;
);

CREATE TABLE Animal_Zookeeper
(
    animal_id VARCHAR(5) NOT NULL,
    employee_id VARCHAR(5) NOT NULL,
    PRIMARY KEY (employee_id, animal_id)
);

-- insert data to Animal/Zookeeper tables

ALTER TABLE Animal_Zookeeper
    ADD CONSTRAINT FK_Animal_Zookeper_Relation_1
    FOREIGN KEY (animal_id)
    REFERENCES Animal(animalID)
    ON UPDATE RESTRICT
    ON DELETE RESTRICT,
    ADD CONSTRAINT FK_Animal_Zookeeper_Relation_2
    FOREIGN KEY (employee_id)
    REFERENCES Zookeeper(employeeID)
    ON UPDATE RESTRICT
    ON DELETE RESTRICT;

I’d like to check if this is the correct way to represent this relationship, or if I’ve missed something out as I’m not completely confident in how this is meant to behave (some clarification would be nice :D). I also have a Zero or More to One or More relationship to represent, is that simply done the same way as above?

Thanks in advance, as I said it’s for an assignment so don’t do it for me, just a bit of checking and some pointers would be helpful :p

  • 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-16T22:13:40+00:00Added an answer on June 16, 2026 at 10:13 pm

    That’s a proper many-to-many setup. For 0/1-to-many, you’d simply eliminate the animal_zookeeper table, and move the relationship into one of the parent animal and/or zookeeper tables, e.g.:

    table animal {
      ...
      zookeeper foreign key ...
    }
    

    this would allow ONE zookeeper to be assigned to an animal, but the same zookeeper could have multiple animals assigned to them. If you require an animal to have a zookeeper, the zookeeper field is “not null”. If you want to have “orphaned” animals with no zookeeper, you allow nulls in the zookeeper field.


    edit: set theory

    view your two tables as sets of records: a set of zookeepers, and a set of animals.

    This is the setup for a 1:many, where the animals are the many, and the zookeepers are the one. Note that the “one” doesn’t mean there’s only one zookeeper. The x:y stuff refers to RECORDS in the tables. one zookeeper record can have many animal records pointing at it. it doesn’t mean you’ve got one zookeeper taking care of the entire zoo.

     table animals {
         id
         zookeeper foreign key (zookeepers.id) default null
     }
    
     table zookeepers {
         id
     }
    

    If you’ve got zookeepers “John” and “Jane”, then any given animal can have either (or neither) assigned to them.

     (many)    (one/none)
     tiger     John
     leopard   John
     monkey    (null)    <--monkey is orphaned, with no zookeeper assigned.
     elephant  Jane
    

    So John is taking care of the tiger and leopard (one zookeeper, many animals), Jane has the elephant (a one:many that happens by chance to be a 1:1), and the monkey is all by itself with no one. But you’d never get John: monkey + Jane: monkey, because the animals can only ever have ONE zookeeper assigned to them.

    To enforce a one:many, meaning no orphaned animals, you’d change your animal to be:

    table animal {
       id
       zookeeper foreign key (zookeepers.id) NOT NULL
                                            ^^^^^^^^^
    }
    

    now the monkey cannot have “no one”, because the database enforces that you assign a zookeeper to the monkey. It’s still a 1:m, but you’ve now dissallowed the 0:m case.

    1:m “there exists exactly ONE X which can have mutiple Y assigned to it”. e.g. one zookeeper can handle multiple animals, but each animal can have only one zookeeper assigned to them. or vice versa – one animal can have multiple keepers, but each keeper can only have one animal

    m:m: wide open, multiple animals associated in varying combinations with multiple zookeepers. This is the most flexible setup, allowing any combination of zookeeper:animal relationships. But its side effect is that it’s difficult to prevent a 0:m situation, without adding CHECK CONSTRAINTS on the zookeeper_animal table, which not all databases support (e.g. mysql).

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

Sidebar

Related Questions

I have an assignment to create a secure communication between 2 people with a
I have written this code as my answer to an assignment I recieved in
This was a homework assignment problem which I know I have incorrectly answered. I
I have an assignment in which I have to allow a user to plot
I have an assignment to create a GUI using MATLAB GUIDE and am having
I have encountered an error which has stumped me for many days now. A
I have a homework assignment in SQL for Oracle 10g where I have to
I have this loop which generates a vector Diff. How do I place the
I have a question relating to the answer on this post Javascript code to
This is an assignment question that I am having trouble wording an answer to.

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.