I have huge table with 1 million records, i wou开发者_开发知识库ld like to modify some of the text columns to varchar column. Which is the best way to modify the columns.
- Alter table query with all modify columns
- Alter table queries with single modify column.
Definitely variant 1, because, as stated in the MySQL documentation,
In most cases, ALTER TABLE makes a temporary copy of the original table. MySQL waits for other operations that are modifying the table, then proceeds. It incorporates the alteration into the copy, deletes the original table, and renames the new one.
So, it's better to have a single copy/wait for operations/delete old table/rename new one operation than multiple ones.
精彩评论