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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:05:44+00:00 2026-06-15T10:05:44+00:00

I’ve been trying to create foreign keys on a table to refer to a

  • 0

I’ve been trying to create foreign keys on a table to refer to a price table, this is the syntax I have so far, which creates errors,

CREATE TABLE shirts(
        shirt_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
        shirt_name VARCHAR(100) NOT NULL,
        shirt_type VARCHAR(10) NOT NULL,
        shirt_size VARCHAR(20) NOT NULL,
        qp_price NUMERIC(6,2) FOREIGN KEY REFERENCES price_list.price ON price_list.price_id=shirts.qp_price NOT NULL,
        o_price NUMERIC(6,2) FOREIGN KEY REFERENCES price_list.price ON price_list.price_id=shirts.o_price NOT NULL,
        clr_options VARCHAR(30) NULL,
        qty NUMERIC(5,0) NULL
    )ENGINE=INNODB

The “price table” has 3 columns, which is price_id, price_cat and price. What I want the qp_price and o_price columns in the shirts table do is show the price column of the price_list table according to the number I put into those columns on the shirts table. For example,

if I do

INSERT INTO shirts(shirt_name,shirt_type,shirt_size,qp_price,o_price)VALUES
        ('Crewneck Tee','Men','S','1','2'),
        ('Crewneck Tee','Men','M','1','2'),
        ('Crewneck Tee','Men','L','1','2'),
        ('Crewneck Tee','Men','1X','1','2'),
        ('Crewneck Tee','Men','2X','3','4'),
        ('Crewneck Tee','Men','3X','5','6'),
        ('Crewneck Tee','Men','4X','7','8'),
        ('Crewneck Tee','Men','5X','9','10')

the S-L crewneck tees would be showing the price in the 1st and 2nd rows of the price column because it’s linking to the price_id column on the price_list table… how can I do this?

  • 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-15T10:05:45+00:00Added an answer on June 15, 2026 at 10:05 am

    The ON in a CREATE TABLE statmenet FOREIGN KEY REFERENCES clause is not a join, it’s meant to specify behavior, like ON UPDATE CASCADE ON DELETE RESTRICT.

    Also, I found this comment regarding MySQL 5.1 at 14.6.4.4. FOREIGN KEY Constraints:

    Ensure that you indexed both Table 1 and Table 2’s referenced columns
    on Table 1 and Table 2 respectively. If you don’t, the error “#1005 –
    Can’t create table ‘prospect’ (errno:105)” will be flagged. (Indexing
    is good practice as it avoids full table-scans!) Once this is taken
    care of and the referenced columns are of same data-type, you would
    have successfully created your desired table with as many FKs as you
    want on it.

    CREATE TABLE shirts(
        shirt_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
        shirt_name VARCHAR(100) NOT NULL,
        shirt_type VARCHAR(10) NOT NULL,
        shirt_size VARCHAR(20) NOT NULL,
        qp_price NUMERIC(6,2) NOT NULL, 
        o_price NUMERIC(6,2) NOT NULL, 
        clr_options VARCHAR(30) NULL,
        qty NUMERIC(5,0) NULL
        INDEX (qp_price),
        INDEX (o_price),
        FOREIGN KEY (qp_price) REFERENCES price_list(price_id),
        FOREIGN KEY (o_price) REFERENCES price_list(price_id),
    )ENGINE=INNODB
    

    FYI, http://www.dpriver.com/pp/sqlformat.htm is pretty useful when you don’t happen to have a particular database environment stood up.

    • 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’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an array which has BIG numbers and small numbers in it. I

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.