Adding a new SQL column with a default value

Viewed 440486

I am looking for the syntax to add a column to a MySQL database with a default value of 0

Reference

10 Answers

This will work for ENUM type as default value

ALTER TABLE engagete_st.holidays add column `STATUS` ENUM('A', 'D') default 'A' AFTER `H_TYPE`;
ALTER TABLE my_table ADD COLUMN new_field TinyInt(1) DEFAULT 0;

Another useful keyword is FIRST and AFTER if you want to add it in a specific spot in your table.

ALTER TABLE `table1` ADD COLUMN `foo` AFTER `bar` INT DEFAULT 0;
Related