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

  • Home
  • SEARCH
  • 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 8045637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:36:40+00:00 2026-06-05T05:36:40+00:00

I am creating a database model with Workbench and create the following table: CREATE

  • 0

I am creating a database model with Workbench and create the following table:

CREATE  TABLE IF NOT EXISTS `Database`.`table1` (
  `idtable1` INT NOT NULL ,
  `uniquecolumn` INT NOT NULL ,
  PRIMARY KEY (`idtable1`) ,
  UNIQUE INDEX `UniqueIndex` (`uniquecolumn` ASC) )
ENGINE = InnoDB

It has a primary key, and a unique key on my second column.

When I create foreign key constraints on them, Workbench automatically adds two indexes:

CREATE  TABLE IF NOT EXISTS `Database`.`table1` (
  `idtable1` INT NOT NULL ,
  `uniquecolumn` INT NOT NULL ,
  PRIMARY KEY (`idtable1`) ,
  UNIQUE INDEX `UniqueIndex` (`uniquecolumn` ASC) ,
  INDEX `FKOne` (`idtable1` ASC) ,                   //here
  INDEX `FKTwo` (`uniquecolumn` ASC) ,               //(I don't want this!)
  CONSTRAINT `FKOne`
    FOREIGN KEY (`idtable1` )
    REFERENCES `Database`.`table2` (`idtable2` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `FKTwo`
    FOREIGN KEY (`uniquecolumn` )
    REFERENCES `Database`.`table2` (`idtable2` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB

(The above is the forward-engineered script after adding the foreign keys to my model)

I have four indexes now.

This is what the MySQL Reference Manual says:

In the referencing table, there must be an index where the foreign key
columns are listed as the first columns in the same order. Such an
index is created on the referencing table automatically if it does not
exist.

So I understand there is no need to create indexes FKOne and FKTwo, since there are already a Primary Key and a Unique index, on the same columns, in the same order. Yet MySQL Workbench doesn’t allow me to delete indexes FKOne and FKTwo. And I think I should be able to do this:

CREATE  TABLE IF NOT EXISTS `Database`.`table1` (
  `idtable1` INT NOT NULL ,
  `uniquecolumn` INT NOT NULL ,
  PRIMARY KEY (`idtable1`) ,
  UNIQUE INDEX `UniqueIndex` (`uniquecolumn` ASC) ,
  CONSTRAINT `FKOne`
    FOREIGN KEY (`idtable1` )
    REFERENCES `Database`.`table2` (`idtable2` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `FKTwo`
    FOREIGN KEY (`uniquecolumn` )
    REFERENCES `Database`.`table2` (`idtable2` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB

Am I right? Would this code work? Is there some way to do it with Workbench? (Apart from deleting those two lines at the last moment before forward-engineering).

Or maybe MySQL is smart enough to refrain from creating totally redundant indexes and I don’t have to worry about it…?

  • 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-05T05:36:42+00:00Added an answer on June 5, 2026 at 5:36 am

    (I’m assuming this is when defining a model.)

    See Bug 53277, where I mention the following obscure workaround:

    You start with a foreign key and its corresponding generated index that you want to get rid of. Make sure the key is (at least temporarily) on a single non-unique column. In the Indexes tab, change the Type to UNIQUE. Then go to the Columns tab, where UQ is now checked, and uncheck it. The unwanted index is eliminated!

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

Sidebar

Related Questions

I am creating a database in SQL server 2008, CREATE TABLE Users ( U_Id
I'm creating a database table and I don't have a logical primary key assigned
I have a problem creating a database schema for the following scenario: (I’m not
I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent
I am creating database tables by the following code: public void createSchema() { Configuration
I am creating database at runtime and I want to create the tables in
I'm creating a model called Configuration and I have the following code and I
So, I am creating a transaction database table to store, well, transactions between the
I am creating a visual representation of my existing database with MySQL Workbench and
When creating a database using Entity Framework code-first, a lot of the database model

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.