Reputation: 1589
I'm trying to find out what I'm missing for my syntax errors to get corrected so I can apply a unique index to a field in my table called vehicleDrive.
ALTER TABLE `vehicleDrive` ADD UNIQUE `name`;
I'm receiving this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Upvotes: 1
Views: 958
Reputation: 1
Here's the syntax:
alter table <table_name>
add unique index <index_name> (<column_name> (8000))
So try something like this:
ALTER TABLE vehicleDrive ADD UNIQUE INDEX index_unique_name (name)
Upvotes: 0
Reputation: 1269873
How about doing:
create unique index idx_vehicleDrive_name on vehicleDrive(name);
This also gives the index a name.
For your syntax, you need parentheses:
ALTER TABLE `vehicleDrive` ADD UNIQUE (name);
Upvotes: 1
Reputation: 42460
You may be missing some brackets around the column name:
ALTER TABLE vehicleDrive ADD UNIQUE (name)
Upvotes: 0