简体   繁体   中英

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?

combine it adding comma, eg

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM