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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:29:30+00:00 2026-05-13T19:29:30+00:00

This is a further discussion on this question: Why is it still possible to

  • 0

This is a further discussion on this question:

Why is it still possible to insert a foreign key that doesn't exist?

This works:

CREATE TABLE products (
     id integer unsigned auto_increment primary key
) ENGINE=INNODB;

CREATE TABLE orders (
     id integer PRIMARY KEY auto_increment,
     product_id integer unsigned,
     quantity integer,
     INDEX product_id_idx (product_id),
     FOREIGN KEY (product_id) REFERENCES products (id)
) ENGINE=INNODB;

But these 2 not:

A

CREATE TABLE products (
     id integer unsigned auto_increment primary key
) ENGINE=INNODB;

CREATE TABLE orders (
    id integer PRIMARY KEY auto_increment,
    product_id integer unsigned REFERENCES products (id),
    quantity integer,
    INDEX product_id_idx (product_id)
);

B

CREATE TABLE products (
     id integer auto_increment primary key
) ENGINE=INNODB;

CREATE TABLE orders (
     id integer PRIMARY KEY auto_increment,
     product_id integer unsigned,
     quantity integer,
     INDEX product_id_idx (product_id),
     FOREIGN KEY (product_id) REFERENCES products (id)
) ENGINE=INNODB;

For B,it’s because integer primary key is the same as integer unsigned primary key

Can you explain why A and B are not working?

  • 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-05-13T19:29:31+00:00Added an answer on May 13, 2026 at 7:29 pm

    A does not work because InnoDB does not recognize or support the syntax for “Inline REFERENCES specifications.” They are simply ignored.

    B does not work because the referencing and referenced columns need to be of the exact same type. “The size and sign of integer types must be the same.” MySQL’s numeric data types are signed by default, so you would have to explicitly specify the unsigned attribute. You can test that INT AUTO_INCREMENT PRIMARY KEY does not imply unsigned:

    CREATE TABLE a (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB;
    INSERT INTO a VALUES(-5);
    SELECT * FROM a;
    

    Source and further reading:

    • MySQL 5.1 Reference Manual: FOREIGN KEY Constraints
    • MySQL 5.1 Reference Manual: Overview of Numeric Types
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question follows on from a previous question, that has raised a further issue.
N.B THIS QUESTION HAS BEEN UPDATED, READ FURTHER DOWN Hi, I want to create
This is an extension question to: how-do-i-create-a-self-signed-certificate-for-code-signing-on-windows To take this further, if I have
This is a further question based on this answer: How can I implement a
Background (question further down) I've been Googling this back and forth reading RFCs and
since I couldn't find an answer to this question I researched a bit further
For ease of discussion, consider this basic table (Test) in Access... ID division name
If I have $('.rotator li').each(function() { $(this).further-nested-elements.somefunction(); }); how can I reference elements that
This is one column of a data frame. I want to further split into
Further to the discussion in Floating div issue in IE i added Floating div

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.