Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: What does KEY id_2 do?

I have been using:

PRIMARY KEY (id), UNIQUE id (id), KEY id_2 (id)

whenever I create a table, but I dont understand what KEY id_2 (id) does and why?

I've searched everywhere and cannot find a suitable answer. Thanks!

like image 933
TimNguyenBSM Avatar asked Jan 29 '26 02:01

TimNguyenBSM


1 Answers

Based on your example, I believe you're creating three different indexes on one column... which probably isn't what you were intending to do.

First, you're creating a primary key:

PRIMARY KEY (id)

Next, you're creating a unique index, which isn't necessary, because you already have the primary key... and you name this unique index id:

UNIQUE id (id)

Finally, you create a third index named id_2:

KEY id_2 (id)

Instead, I think you should be creating just the primary key, and forgo the other two indexes.

like image 85
Michael Fredrickson Avatar answered Jan 31 '26 16:01

Michael Fredrickson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!