Wednesday, December 18, 2024

SQL DROP DEFAULT Keyword

 The DROP DEFAULT keyword in SQL is used to remove a default value that has been assigned to a column in a database table. This is typically used when you want to stop a column from automatically assigning a default value when no value is provided during an insert operation.

Syntax:

ALTER TABLE table_name
MODIFY column_name DROP DEFAULT;

Example:

Suppose you have a table named employees and a column salary that has a default value of 50000. If you want to remove this default, you would use the following SQL command:

ALTER TABLE employees
MODIFY salary DROP DEFAULT;

Notes:

  • The DROP DEFAULT operation removes the default value set on the column, meaning that if no value is provided for the column during an insert, it will be NULL (unless the column is set as NOT NULL).
  • Different database management systems (DBMS) may have slightly different syntax for this operation, so be sure to refer to the documentation for your specific DBMS (such as MySQL, PostgreSQL, or SQL Server).

No comments:

Post a Comment