SQL DROP DEFAULT Keyword



Purpose

The DROP DEFAULT command removes a default constraint from a column in a table. A default constraint specifies a default value for a column; if you don't provide a value when inserting a new row, the default value is automatically used. DROP DEFAULT removes this automatic assignment.

Syntax and Usage

The syntax for DROP DEFAULT varies slightly depending on the specific database system you're using.

SQL Server, Oracle, and MS Access

In SQL Server, Oracle, and MS Access, the syntax is:

Syntax

ALTER TABLE table_name
ALTER COLUMN column_name DROP DEFAULT;
            

Replace table_name with the name of your table and column_name with the name of the column you want to remove the default constraint from.

Example (SQL Server, Oracle, MS Access)

ALTER TABLE Persons
ALTER COLUMN City DROP DEFAULT;
            

MySQL

In MySQL, the syntax is slightly different:

Syntax

ALTER TABLE table_name
ALTER column_name DROP DEFAULT;
            

Again, remember to replace table_name and column_name with your specific table and column names.

Example (MySQL)

ALTER TABLE Persons
ALTER City DROP DEFAULT;