Reputation: 2269
I have this existing query to create an additional MySQL column to an existing table.:
$wpdb->query("ALTER TABLE mytable ADD COLUMN myarguments VARCHAR(255)");
How can I also create indexes while adding new column?
Upvotes: 24
Views: 31308
Reputation: 868
To create indexes, use the CREATE INDEX command:
CREATE INDEX index_name ON table_name (column_name);
To drop a non-primary key index, use the DROP INDEX command:
DROP INDEX index_name ON table_name;
Upvotes: -1
Reputation: 263713
combine it adding comma, eg
ALTER TABLE mytable
ADD COLUMN myarguments VARCHAR(255),
ADD INDEX (myarguments);
Upvotes: 45