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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:17:35+00:00 2026-05-26T16:17:35+00:00

I have a table called Order_List that contains a list of orders. Each column

  • 0

I have a table called Order_List that contains a list of orders. Each column contains a foreign key that references the primary key of an order in the order table. My question is, what is the best way to declare these foreign keys. Using MySQL Workbench I found two ways…

Method #1

CREATE  TABLE IF NOT EXISTS 'mydb'.'Order_List' (
    'idOrder_List' INT UNSIGNED NOT NULL AUTO_INCREMENT ,
    'orderID01' INT UNSIGNED NULL ,
    'orderID02' INT UNSIGNED NULL ,
    'orderID03' INT UNSIGNED NULL ,
    'orderID04' INT UNSIGNED NULL ,
    PRIMARY KEY ('idOrder_List') ,
    INDEX 'fk_Order_List_1' ('orderID01' ASC, 'orderID02' ASC, 'orderID03' ASC, 'orderID04' ASC) ,
    CONSTRAINT 'fk_Order_List_1'
      FOREIGN KEY ('orderID01' , 'orderID02' , 'orderID03' , 'orderID04' )
      REFERENCES 'mydb'.'Order' ('idOrder' , 'idOrder' , 'idOrder' , 'idOrder' )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
    ENGINE = InnoDB

Method #2

  CREATE  TABLE IF NOT EXISTS 'mydb'.'Order_List' (
    'idOrder_List' INT UNSIGNED NOT NULL AUTO_INCREMENT ,
    'orderID01' INT UNSIGNED NULL ,
    'orderID02' INT UNSIGNED NULL ,
    'orderID03' INT UNSIGNED NULL ,
    'orderID04' INT UNSIGNED NULL ,
    PRIMARY KEY ('idOrder_List') ,
    INDEX 'fk_Order_List_1' ('orderID01' ASC) ,
    INDEX 'fk_Order_List_2' ('orderID02' ASC) ,
    INDEX 'fk_Order_List_3' ('orderID03' ASC) ,
    INDEX 'fk_Order_List_4' ('orderID04' ASC) ,
    CONSTRAINT 'fk_Order_List_1'
      FOREIGN KEY ('orderID01' )
      REFERENCES 'mydb'.'Order' ('idOrder' )
      ON DELETE CASCADE
      ON UPDATE CASCADE,
    CONSTRAINT 'fk_Order_List_2'
      FOREIGN KEY ('orderID02' )
      REFERENCES 'mydb'.'Order' ('idOrder' )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT 'fk_Order_List_3'
      FOREIGN KEY ('orderID03' )
      REFERENCES 'mydb'.'Order' ('idOrder' )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT 'fk_Order_List_4'
      FOREIGN KEY ('orderID04' )
      REFERENCES 'mydb'.'Order' ('idOrder' )
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
    ENGINE = InnoDB

The first method combines the declaration. The second method splits it up. Which one is better? Are there any inherent weaknesses to one over the other? Thanks!

  • 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-26T16:17:36+00:00Added an answer on May 26, 2026 at 4:17 pm

    This isn’t the same FK.

    • One ensures that the combination of the 4 columns in any OrderList row exist in a single row row in 'mydb'.'Order'
    • The other ensures that the 4 column values in any OrderList row exist independently of the others in some 'mydb'.'Order' row
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a products table with a column that contains a space separated list
I have a table called order which contains columns id , user_id , price
I have a table called orders this table contains all the information we need.
i have table called as Support, which have a field named Name and contains
I have table called Buttons. Buttons table i have column button_number . Table contain
I have table called posts in my DB. Each post has field called social_network
I have a table called scheduler_sched which has several columns, including a column called
Here's what I'm doing: List<Category> categories = db.Categories.Include(SubCategories).OrderBy(c => c.Order).ToList(); I have a column
I have a list of objects (called Phases) that I'm storing in a db
I have two tables called 'events' and 'topics' each table can have many comments.

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.