What is the meaning of the "indexing equal or removed" error in Mysql?

Asked

Viewed 162 times

0

erro indices

I am working with small relationships and I realized that in a state table in which I related the field id the table país[id] I get this error message or alert, I’m not sure. Already in a table relationship cidade the table estado[id] I don’t have this mistake.

Can help me to know why this error occurs in the relationship estado - país?

My SQL is this:

$criar      = "CREATE TABLE IF NOT EXISTS $aonde.$tablee (
        id          INT(6)  UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
        nome        VARCHAR(75) DEFAULT NULL,
        uf          VARCHAR(5) DEFAULT NULL,
        pais        INT(6) UNSIGNED ZEROFILL DEFAULT NULL, 
                    PRIMARY KEY (id), KEY fk_Estado_pais (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=28";
  • think q vc has to set the fk_Estado_parents ... type in mysql would be : Foreign key(parents) References fk_Estado_parents(id).

1 answer

7

This error indicates that you have two equal indexing keys, where you are essentially repeating data in the table indexing. Mysql warns because duplicate indexing ultimately affects query performance.

In your SQL is visible the duplication in question:

PRIMARY KEY (id), KEY fk_Estado_pais (id)

You have your primary table key in the field id and then you have a new indexing key in the same field id with the name fk_Estado_pais.

The mistake you get:

The index PRIMARY and fk_Estado_pais appear to be the same or one of them may have been removed.

It seems to me to be poorly translated compared to its original because the information given by it does not match the information in the index table or with the information in your SQL. But it is an assumption because only with the Mysql code associated with this error can I know the original details of it.

Solution

For indexing according to your description, using only PRIMARY KEY(id) is more than sufficient since it is an indexed and unique value that allows an excellent relationship with the other table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.