How do I alter a mysql table column defaults?

Pete was almost correct but used the wrong syntax for ‘change’: ALTER TABLE mytable CHANGE `time` `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP Notice that you must repeat the column name. Also, make sure you are using backticks instead of single quotes to escape the column name time, which prevents it from being interpreted as the … Read more

SQL Server: how to write an alter index statement to add a column to the unique index?

You cannot alter an index – all you can do is drop the old index (DROP INDEX (indexname) ON (tablename)) re-create the new index with the additional column in it: CREATE UNIQUE NONCLUSTERED INDEX (indexname) ON dbo.YourTableName(columns to include) The ALTER INDEX statement in SQL Server (see docs) is available to alter certain properties (storage … Read more

ALTER TABLE ADD COLUMN takes a long time

Your ALTER TABLE statement implies mysql will have to re-write every single row of the table including the new column. Since you have more than 2 million rows, I would definitely expect it takes a significant amount of time, during which your server will likely be mostly IO-bound. You’d usually find it’s more performant to … Read more