I have the following table, which enforces a foreign key on vendor_id:
CREATE TABLE `notes` (
`vendor_id` varchar(20) NOT NULL DEFAULT '',
KEY `vendor_id` (`vendor_id`),
CONSTRAINT `notes_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `title` (`vendor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I was looking over someone else’s table, and it had the KEY, but did not show a CONSTRAINT, as follows:
CREATE TABLE `notes` (
`vendor_id` varchar(20) NOT NULL DEFAULT '',
KEY `vendor_id` (`vendor_id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What exactly does this mean / do to have a KEY without anything else?
KEYis a synonym forINDEX, so in this case,vendor_idhas had an index created on it, but has not specifically been defined as the table’sPRIMARY KEY, which would enforce uniqueness.From the MySQL
CREATE TABLEdocs: