How can default values be set for a table in MySQL?

You can use the ALTER TABLE statement to set a default value for a table. For example, here is an example SQL statement to set a default value for a column in a table:

ALTER TABLE your_table_name
ALTER COLUMN column_name SET DEFAULT default_value;

In the example above, “your_table_name” refers to the name of the table where you want to set a default value, “column_name” refers to the name of the column you want to set a default value for, and “default_value” is the value you want to set as the default.

Please note that if you want to set a default value for a new column, you can specify it when creating the table, for example:

CREATE TABLE your_table_name (
    column_name datatype DEFAULT default_value
);
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds