In MySQL, the default value of a column can be set to 1 using the ALTER TABLE statement and the DEFAULT keyword. The steps are as follows: 1. Determine the table name and column name; 2. Write the ALTER TABLE statement; 3. Execute the statement.
In MySQL, you can pass theALTER TABLE
statement and ## The #DEFAULTkeyword sets the column's default value to 1.
ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 1;
1. Determine the table name and column name
First, you need to know the table name to be updated Name and the name of the column for which you want to set the default value.2. Write theALTER TABLEstatement
ALTER TABLEstatement, specify the table name, column name and default value.
3. Execute statement
ExecuteALTER TABLEstatement in MySQL command line or client:
mysql> ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT 1;
my_columnin a table named
my_table, and you want to set the default value of the column to 1. Then, you need to execute the following statement:
ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT 1;
my_columncolumn will default to 1 without explicitly specifying a value.
statement will overwrite it.
constraint to enforce a default value.
The above is the detailed content of How to set the default value to 1 in mysql. For more information, please follow other related articles on the PHP Chinese website!