-----------------------------------------------------------ALTER TABLE CREATE index-----------------------------------------------------------Create primary key alter TABLE ' table_name ' ADD CONSTRAINT PRIMARY KEY (' column '); --Create PRIMARY key alter TABLE ' table_name ' ADD PRIMARY key (' column '); --Create a unique index alter TABLE ' table_name ' ADD unique index_name (' column '); --Create full-text index alter TABLE ' TABLE_NAME ' ADD fulltext index_name (' column '); --Create an ordinary index alter TABLE ' table_name ' ADD index index_name (' column '); --Create an ordinary combination index alter TABLE ' table_name ' ADD index index_name (' Column1 ', ' column2 ', ' column3 '); --Delete primary key alter TABLE ' table_name ' DROP PRIMARY key; --delete index alter TABLE ' table_name ' DROP index index_name; /* When removing the self-increment primary key, first modify the self-increment column to be non-self-increment, eg:alter TABLE ' table_name ' MODIFY column ' column ' int default 0; Then delete the primary key. Eg:alter TABLE ' table_name ' DROP PRIMARY key;*/-----------------------------------------------------------CREATE Create an index-----------------------------------------------------------create unique index index_name on ' table_name ' (' column '); --Creating a full-text index create FULLTEXT index_name on ' table_name ' (' column '); --Create INDEX index_name on ' table_name ' (' column ') for normal indexes; --Create INDEX index_name on ' table_name ' (' column1 ', ' column2 ', ' column3 '). --Drop index index_name on ' talbe_name '; -----------------------------------------------------------Modify a table field-------------------------------------------------------- ---delete field alter TABLE ' table_name ' DROP column ' column '; --Add Field ALTER TABLE ' table_name ' ADD COLUMN ' column ' TYPE [NULL] [DEFAULT] [COMMENT]; --Example: ALTER TABLE ' users ' ADD COLUMN ' username ' varchar (a) NOT null default ' COMMENT ' username ';--modify field ALTER TABLE ' Table_na Me ' MODIFY column ' column ' TYPE [NULL] [DEFAULT] [COMMENT]; --Modify the field name alter TABLE ' table_name ' change ' old_column ' new_column ' TYPE;
MySQL CREATE INDEX, delete index, add field, delete field, modify field statement