Like the title says I'm getting the following error when inserting this query into the MySQL Command Line Client
Query
ALTER TABLE physician ADD UNIQUE (ssn);
Error code
ERROR 1062 (23000): Duplicate entry '' for key 'physician.ssn'
I don't know why I'm pulling a duplicate entry error as this shouldn't be a duplicate entry. Any help is appreciated.
A unique constraint will only allow unique values for that column. Since you already have many rows with NULL, MySQL will not allow you to add the constraint.
You have 2 options:
The syntax would be:
CREATE UNIQUE INDEX physician_ssn_idx ON physician(ssn);
physician_ssn_idx
will be the name of the newly created index, which can be anything you want it to be. If you have been creating index/key using a naming scheme you might want to adopt that. Ultimately, the names of indexes don't effect the functionality at all, and you don't need to know them in order to make use of them.