SQL Add Column to Table with Default Value
Sometimes it is required to add new column to the table with default value.
Just adding new column may create new column with null values to existing rows. This might not be the right values for existing rows. In that case, you may want to add new column with default value so that old rows can have that value.
Lets assume that you have a table 'customer'. You already have few thousand customers saved on that table. Somehow you forgot to create column "country" and now you want to add that column. You want to keep default country as "USA".
Use following syntax of sql alter table to add new column with default value:
ALTER TABLE customer ADD COLUMN country VARCHAR(50) NOT NULL DEFAULT "USA";