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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:46:49+00:00 2026-06-06T19:46:49+00:00

I am trying to create a series of tables with multiple foreign key relationships.

  • 0

I am trying to create a series of tables with multiple foreign key relationships. The first of the two tables have a two-column primary key, once specified by us and the other specified by the manufacturer. The error is occurring when the third query is attempted. I’m not really sure what is going wrong here so any help would be sincerely appreciated.

SQL

CREATE TABLE rugs (
    id INTEGER NOT NULL AUTO_INCREMENT,
    manufacturer_id INTEGER NOT NULL,
    name VARCHAR(255),
    description TEXT,
    PRIMARY KEY (id, manufacturer_id)
);

CREATE TABLE carpets (
    id INTEGER NOT NULL AUTO_INCREMENT,
    manufacturer_id INTEGER NOT NULL,
    name VARCHAR(255),
    warranty TEXT,
    description TEXT,
    fiber_name VARCHAR(255),
    brand_name VARCHAR(255),
    texture_name VARCHAR(255),
    PRIMARY KEY (id, manufacturer_id)
);

CREATE TABLE carpet_styles (
    id INTEGER NOT NULL AUTO_INCREMENT,
    carpet_id INTEGER,
    style_name VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);

CREATE TABLE carpet_colors (
    id INTEGER NOT NULL AUTO_INCREMENT,
    carpet_id INTEGER,
    color_name VARCHAR(255),
    color_category VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);

CREATE TABLE carpet_custom_names (
    id INTEGER NOT NULL AUTO_INCREMENT,
    carpet_id INTEGER,
    custom_name VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);

CREATE TABLE rug_styles (
    id INTEGER NOT NULL AUTO_INCREMENT,
    rug_id INTEGER,
    style_name VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);

CREATE TABLE rug_colors (
    id INTEGER NOT NULL AUTO_INCREMENT,
    rug_id INTEGER,
    color_name VARCHAR(255),
    color_category VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);

CREATE TABLE rug_shapes (
    id INTEGER NOT NULL AUTO_INCREMENT,
    rug_id INTEGER,
    shape_name VARCHAR(255),
    shape_category VARCHAR(255),
    PRIMARY KEY (id),
    FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);

CREATE TABLE catalog_contents (
    id INTEGER NOT NULL AUTO_INCREMENT,
    catalog_id INTEGER,
    carpet_id INTEGER,
    rug_id INTEGER,
    PRIMARY KEY (id),
    FOREIGN KEY (rug_id) REFERENCES rugs (id),
    FOREIGN KEY (carpet_id) REFERENCES carpets (id),
    FOREIGN KEY (catalog_id) REFERENCES catalogs (id)
);
  • 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-06T19:46:51+00:00Added an answer on June 6, 2026 at 7:46 pm

    This appears to be due to the fact that although carpets.manufacturer_id is part of a composite key, it has no index of its own. You must create an index on it separately from the composite PRIMARY KEY. The same is true for rugs.manufacturer_id

    CREATE TABLE rugs (
        id INTEGER NOT NULL AUTO_INCREMENT,
        manufacturer_id INTEGER NOT NULL,
        name VARCHAR(255),
        description TEXT,
        /* manufacturer_id gets its own index */
        PRIMARY KEY (id, manufacturer_id),
        INDEX idx_rugs_manufacturer_id (manufacturer_id)
    );
    
    
    CREATE TABLE carpets (
        id INTEGER NOT NULL AUTO_INCREMENT,
        manufacturer_id INTEGER NOT NULL,
        name VARCHAR(255),
        warranty TEXT,
        description TEXT,
        fiber_name VARCHAR(255),
        brand_name VARCHAR(255),
        texture_name VARCHAR(255),
        PRIMARY KEY (id, manufacturer_id),
        /* manufacturer_id gets its own index */
        INDEX idx_manufacturer_id (manufacturer_id)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a pretty simple scatter plot with two data series. I
I am trying to create a series of dynamic, calculated fields on my window.
I'm trying to create a series of bound columns in a RadGridView, and I'm
I am trying to create an NSTextView that behaves somewhat like a series of
I am trying to create a static global array called series. But the number
I am trying to create a gradient fill for a series in an area
I am trying to create a menu which is a series of floated li
I'm trying to create a loop that creates a series of objects that contains
I'm trying to create a <div> with a series of photos which are horizontally
I am trying to create a stacked column chart in VBA where there is

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.