How to Remove a Default Value from a Column in MySQL

In MySQL, removing the default value from a column can be necessary when you want to update your table schema or correct a configuration. This tutorial explains how to alter a column to remove its default value.

Steps to Remove a Default Value

Follow these steps to remove a default value from a column in MySQL:

  1. Step 1: Connect to MySQL Database
    First, connect to your MySQL database using the MySQL command line or your preferred MySQL client. For example:
  2. mysql -u username -p
  3. Step 2: Use the ALTER TABLE Command
    To remove a default value from a column, use the ALTER TABLE command with the MODIFY statement. The syntax is as follows:
  4. ALTER TABLE table_name MODIFY column_name column_definition;

    For example, if you want to remove the default value from a column called status in the orders table, you would write:

    ALTER TABLE orders MODIFY status VARCHAR(50) NULL;

    This command modifies the status column to remove its default value, and sets it to NULL instead.

  5. Step 3: Verify the Changes
    To verify that the default value has been removed, you can describe the table:
  6. DESCRIBE table_name;

    If the default value is removed successfully, the column's default value should be displayed as NULL or as an empty value.

    Conclusion

    Removing a default value from a column in MySQL is straightforward using the ALTER TABLE command. Make sure to verify your changes by describing the table after modification. This action can help you adjust your database schema as required.