Emerson Maningo
Emerson Maningo

Reputation: 2269

Add new MySQL table columns and creating indexes

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

Answers (2)

Nazmul Haque
Nazmul Haque

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

John Woo
John Woo

Reputation: 263713

combine it adding comma, eg

ALTER TABLE mytable 
    ADD COLUMN myarguments VARCHAR(255), 
    ADD INDEX (myarguments);

Upvotes: 45

Related Questions