When I use MySQL Workbench to create a simple table with a single primary key, it not only creates the PK index (cool) but also a second Unique Index (?). Here’s an example output:
CREATE TABLE `tbl_example` (
`tbl_example_ID` INT(10) UNSIGNED NOT NULL ,
`field1` VARCHAR(45) NULL ,
`field2` VARCHAR(45) NULL ,
PRIMARY KEY (`tbl_example_ID`) ,
UNIQUE INDEX `tbl_example_ID_UNIQUE` (`tbl_example_ID` ASC) )
ENGINE = MyISAM
It’s my understanding that a PK assumes unique index so the UNIQUE INDEX line is unnecessary, correct? Just looking for some confirmation before I update a bunch of tables.
You are right. A Primary Key is (for MySQL) a unique index with the name ‘PRIMARY KEY’. So having a Primary Key and a unique index on the same column(s) is a pointless waste of resources.