Adding a Column with Default Value in SQL
When extending an existing MySQL database, it may become necessary to add a new column with a predefined default value. To address this, this article will provide a comprehensive guide on the syntax required for such an operation.
Syntax
ALTER TABLE table_name ADD COLUMN column_name data_type DEFAULT default_value;
For instance, to add a column named "score" to a table named "scores" with a default value of 0, the following command can be used:
ALTER TABLE scores ADD COLUMN score INT DEFAULT 0;
Breakdown of the Syntax
Note: It's crucial to ensure that the specified default value is compatible with the data type of the column. For instance, for an INT column, the default value should be an integer.
The above is the detailed content of How to Add a Column with a Default Value in MySQL?. For more information, please follow other related articles on the PHP Chinese website!