I need to add two DATE columns to an already existing table. But it takes very long and I have to kill the process. What is strange is I was able to add those columns to the other tables in the same database momentarily. Most of those tables are larger than the one I'm having trouble with both data and column-count-wise. What do I have to do to be able to add those new columns?
here's how I solved the problem. Before, I was specifying a default value for the columns right at the moment of adding them. But then I first added the columns with no default values. After columns got added I specified the default value and it executed immediately with no more waiting. Thank you very much @Justin Cave for your hint about Default value. That was the key point.
I have no doubt that it's related with the fact that when specifying default value at the time of adding column that default value is written to all the records inserted earlier.So if there are 5 million records in the table, that table will be updated to set default value for the newly added column for all the rows. Updating 5 million records is expensive as one might guess. But if default value is set after adding a column then the value of that new column in the rows inserted earlier will be NULL, so no update will take place.