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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:00:49+00:00 2026-06-16T00:00:49+00:00

I’m trying to create relationships in MySQL using forein keys. Everytime I successfully create

  • 0

I’m trying to create relationships in MySQL using forein keys. Everytime I successfully create the forien key, but when I describe the table, the key is considered “MUL”. After inserting some records into the parent table, I get null values in the child. I’ve been researching this for hours and have come up empty handed. I even checked the innodb status and have no foreign key error reports. I’m not entirely sure why I’m getting null values, but I’m assuming its because of the “MUL” key value. Can someone confirm this and try and help me out?

create table employee
( id int
, first varchar(128)
, last varchar(128)
, primary key(id)
) engine=innodb; 

create table borrow
(ref auto_increment
, empID int
, book varchar(128)
, primary key(ref) 
) engine=innodb; 

alter table borrow add constraint fk_borrow
  foreign key (empID) references employee(id);

insert into borrow (empID, book) values (1,'mike');
  • 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-16T00:00:50+00:00Added an answer on June 16, 2026 at 12:00 am

    The ‘MUL’ just means that it’s not a unique index (i.e. duplicate values are allowed for the KEY). (If it were a unique index, the Key column would show ‘UNI’). The FOREIGN KEY constraint doesn’t have anything to do with the uniqueness of the foreign key column… it normally is non-unique… a parent can usually have zero, one or more children.

    The FOREIGN KEY constraint does not disallow NULL values in the child table. Only a NOT NULL constraint (or a trigger) will do that for you. It’s perfectly reasonable for a row in a child table to be an orphan, to not be related to a parent.

    When you do the INSERT to the child table, you need to provide a non-NULL value for the foreign key column, if you want that row to reference a row in the parent table.


    A foreign key can be defined with an ON DELETE SET NULL clause, but that would only be effective if you were to later delete a parent row that had children related to it. In that case, the child rows would have their foreign key column values set to NULL when the parent row is removed.


    Mike said: I’m concerned that the child’s foreign key is not getting populated by the parent.

    The parent is not responsible for populating the foreign key column of the child. There’s an option to have the child’s foreign key value updated automatically when the parent’s id value is changed… preserving the relationship: ON UPDATE CASCADE. But other than the actions performed by an ON UPDATE or ON DELETE clause, the parent has no responsibility of maintaining the values in a child table.

    Mike asked: So how would I get the child’s column to be populated from the parent?

    You wouldn’t. You would first locate (or insert) the row to the parent table. You would then preserve the value of the id column (or the values of whatever columns make up the PRIMARY KEY), and then use that same value for the foreign key column on the child row, when you insert a child row(s).

    An error is returned when you set a foreign key to an arbitrary value (a value that does not match an existing PRIMARY KEY value in the parent table. That’s the expected behavior.

    If you are inserting the child row before the parent, you will need to leave the foreign key column as NULL, and then after you know the id value of the parent, you would then update the child row to set the foreign key column.


    create table employee
    ( id int
    , first varchar(128)
    , last varchar(128)
    , primary key(id) ) engine=innodb; 
    
    create table borrow 
    (ref auto_increment
    , empID int
    , book varchar(128)
    , primary key(ref) ) engine=innodb;
    
    alter table borrow add constraint fk_borrow
      foreign key (empID) references employee(id);
    
    insert into employee (id, first, last) values (1, 'foo', 'bar');
    
    insert into borrow (empID, book) values (1,'mike');
    
    insert into borrow (empID, book) values (1,'mulligan');
    

    The two rows added to the borrow table are related to the row in employee, by virtue of the value in the foreign key column (empID) being set to a value that matches an id value in the employee table.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.