How can default values be set when creating a table in MySQL?
In MySQL, you can use the DEFAULT keyword to set the default value for a column.
For example, the following sample code creates a table named “students” with three columns: id, name, and age. The default value for the id column is NULL, for the name column is ‘Unknown’, and for the age column is 0.
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50) DEFAULT 'Unknown',
age INT DEFAULT 0
);
In the example above, when inserting a new row into the students table without explicitly specifying values for the name and age columns, they will be automatically set to their default values.