I couldn't find this behavior described in the official MySQL documentation

A few minutes of looking in the MySQL docs found this:

Column values can be given in several ways:

If you are not running in strict SQL mode, any column
not explicitly given a value is set to its default
(explicit or implicit) value. For example, if you specify a
column list that does not name all the columns in the
table, unnamed columns are set to their default values.
Default value assignment is described in Section 11.6,
“Data Type Default Values”. See also Section 1.8.3.3,
“Constraints on Invalid Data”.

If you want an INSERT statement to generate an error unless
you explicitly specify values for all columns that do not
have a default value, you should use strict mode. See
Section 5.1.7, “Server SQL Modes”.
Answer from Mike on serverfault.com
Discussions

MySQL change column default to not null - Stack Overflow
UPDATE test SET views = 0 WHERE ... int NOT NULL DEFAULT 0; Here's the SQL Fiddle (commenting out update statement will result in the same error). ... Sign up to request clarification or add additional context in comments. ... Stack Overflow chat opening up to all users in January; Stack Exchange chat... 0 how i can set default value in mysql field to ... More on stackoverflow.com
🌐 stackoverflow.com
mysql - Remove default value from NOT NULL column - Database Administrators Stack Exchange
ALTER TABLE items CHANGE ordering ... ordering int NOT NULL; ALTER TABLE items ALTER ordering DROP DEFAULT ; ... I never noticed that CHANGE/MODIFY remove the default if it is not specified! I'm amazed that hasn't bitten me yet. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 6 Why mysql throws "invalid ... More on dba.stackexchange.com
🌐 dba.stackexchange.com
October 18, 2018
MySQL default value on NULL - Stack Overflow
CREATE TABLE `Foo` ( `id` int NOT NULL, `FirstName` varchar(255) NULL, `LastName` varchar(255) NOT NULL DEFAULT 'NONE', PRIMARY KEY (`id`) ); When I run the following query it take the default value of 'NONE': ... What I want to achieve is that if a value is NULL then MySQL should use the DEFAULT ... More on stackoverflow.com
🌐 stackoverflow.com
mysql - Field both NOT NULL and DEFAULT NULL - Database Administrators Stack Exchange
This MySQL table had me perplexed for a moment: mysql> desc quux; +---------------------------+-----------------------+------+-----+---------+----------------+ | Field | Typ... More on dba.stackexchange.com
🌐 dba.stackexchange.com
November 23, 2016
🌐
TutorialsPoint
tutorialspoint.com › how-to-set-default-value-to-null-in-mysql
How to set default value to NULL in MySQL?
Use DEFAULT keyword in MySQL to set default value to NULL. Let us first create a − · mysql> create table DemoTable1440 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) DEFAULT NULL, -> StudentAge int DEFAULT NULL -> ); Query OK, 0 rows affected (0.55 sec)
Top answer
1 of 2
4

The answer is to use the following (slightly odd) syntax:

ALTER TABLE items ALTER ordering DROP DEFAULT;
2 of 2
2

When trying to modify a column with ALTER TABLE, there are 4 keywords that can be used, each with different capabilities:

  • CHANGE [COLUMN]
  • MODIFY [COLUMN]
  • RENAME COLUMN
  • ALTER [COLUMN]

CHANGE is a MySQL extension to standard SQL. MODIFY and RENAME COLUMN are MySQL extensions for Oracle compatibility.

ALTER [COLUMN] is standard SQL (I think).

The docs about ALTER TABLE have more details:

Renaming, Redefining, and Reordering Columns

The CHANGE, MODIFY, RENAME COLUMN, and ALTER clauses enable the names and definitions of existing columns to be altered. They have these comparative characteristics:

  • CHANGE:

    • Can rename a column and change its definition, or both.
    • Has more capability than MODIFY or RENAME COLUMN, but at the expense of convenience for some operations. CHANGE requires naming the column twice if not renaming it, and requires respecifying the column definition if only renaming it.
    • With FIRST or AFTER, can reorder columns.
  • MODIFY:

    • Can change a column definition but not its name.
    • More convenient than CHANGE to change a column definition without renaming it.
    • With FIRST or AFTER, can reorder columns.
  • RENAME COLUMN:

    • Can change a column name but not its definition.
    • More convenient than CHANGE to rename a column without changing its definition.
  • ALTER:

    • Used only to change a column default value.

In this case, you have 3 options:

ALTER TABLE items
    CHANGE ordering ordering int NOT NULL;

ALTER TABLE items 
    MODIFY ordering int NOT NULL;

ALTER TABLE items
    ALTER ordering DROP DEFAULT ;
🌐
TutorialsPoint
tutorialspoint.com › adding-a-column-whose-value-is-not-null-by-default-in-mysql
Adding a column whose value is not null by default in MySQL?
For this, you need to remove the default keyword. The syntax is as follows: ALTER TABLE yourTableName ADD COLUMN yourColumnName dataType NOT NULL AFTER yourColumnName; To understand the above syntax, let us create a table. The query to create a table is as follows: mysql> create table ...
🌐
Webmaster World
webmasterworld.com › databases_sql_mysql › 4943726.htm
MySQL: default none or null? - Databases forum at WebmasterWorld - WebmasterWorld
From my experience, every fraction of a second that I can save on a page load results in an increase of pages per session, so saving 100ms on a few queries could have a significant long term financial impact. As for coding, after playing around today it looks like I can leave it as NOT NULL and default to None, and then:
Find elsewhere
🌐
PopSQL
popsql.com › learn-sql › mysql › how-to-remove-a-not-null-constraint-in-mysql
How to Remove a Not Null Constraint in MySQL - PopSQL
To remove a NOT NULL constraint for a column in MySQL, you use the ALTER TABLE .... MODIFY command and restate the column definition, removing the NOT NULL attribute. --Example: Products have a default stock of 0 ALTER TABLE products MODIFY ...
🌐
W3Schools
w3schools.com › mysql › mysql_notnull.asp
MySQL NOT NULL Constraint
CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int ); To define a NOT NULL constraint on an existing table, use ALTER TABLE and add NOT NULL after the data type of the column name.
🌐
PopSQL
popsql.com › learn-sql › mysql › how-to-add-a-not-null-constraint-in-mysql
How to Add a Not Null Constraint in MySQL
To enforce NOT NULL for a column in MySQL, you use the ALTER TABLE .... MODIFY command and restate the column definition, adding the NOT NULL attribute. --Example: Products have a default stock of 0 ALTER TABLE products MODIFY stocks INT NOT NULL;
Top answer
1 of 2
41

As documented under Data Type Default Values:

If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause.

(I think they meant implicit, not explicit).

Moreover, as documented under CREATE TABLE Syntax:

If neither NULL nor NOT NULL is specified, the column is treated as though NULL had been specified.

Therefore, in MySQL the following column definitions are all identical:

columnname type
columnname type NULL
columnname type DEFAULT NULL
columnname type NULL DEFAULT NULL

The choice of which to use is a balance between being explicit, and being concise. Depending on the circumstances, I might use any of the above.

2 of 2
18

Every database that I've encountered treats NULLs the way that you describe them. When a column accepts NULL values, then not providing a value on INSERT defaults the value to NULL. I believe this is part of the ANSI standard behavior.

As for specifying "NULL" itself. That is a matter of preference. The standard does say that a column allows NULLs unless NOT NULL is specified (at the level of the data definition language). So, the NULL itself is unnecesary, and you have a fourth, equivalent option:

columnname type

NULLs are quite embedded in the SQL language through the ANSI standard. Your third option is the most explicit, but it also looks a bit unusual.

If you are planning on being super-consistent throughout your system, then I would take the path you are on. For every column in every table have NULL or NOT NULL. For all columns that take default values, have the DEFAULT statement.

However, don't expect other people you work with (now or in the future) to readily follow this example. Many would prefer the fourth option in this case simply because it requires less typing and is how all (or almost all) SQL dialects behave.

🌐
GitHub
github.com › h2database › h2database › issues › 1940
MySQL Mode: Modify column from NOT NULL to NULL syntax · Issue #1940 · h2database/h2database
May 23, 2019 - In mysql, I can safely omit the null keyword and mysql knows by default it will be nullable. alter table user_download modify column download_dir varchar(255); While in h2database w/ mysql mode, I have to explicitly specify the null, or the ...
Published   May 23, 2019
Author   bood
🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › data-type-defaults.html
MySQL :: MySQL 8.0 Reference Manual :: 13.6 Data Type Default Values
May 20, 2022 - If a default value evaluates to a data type that differs from the declared column type, implicit coercion to the declared type occurs according to the usual MySQL type-conversion rules. See Section 14.3, “Type Conversion in Expression Evaluation”. If a data type specification includes no explicit DEFAULT value, MySQL determines the default value as follows: If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause. For data entry into a NOT NULL column that has no explicit DEFAULT clause, if an INSERT or REPLACE statement includes no value for the column, or an UPDATE statement sets the column to NULL, MySQL handles the column according to the SQL mode in effect at the time:
🌐
Stack Overflow
stackoverflow.com › questions › 55375070 › sql-set-default-value-to-null-for-all-columns-without-default-value
mysql - SQL: Set default value to NULL for all columns without default value - Stack Overflow
SELECT CONCAT( 'ALTER TABLE ', table_name, ' MODIFY COLUMN `', column_name, '` ', data_type, IF(data_type IN ('varchar', 'char'), CONCAT('(', character_maximum_length, ')'), ''), ' NULL DEFAULT NULL;' ) AS alter_statement FROM information_schema.columns WHERE table_schema = 'YOUR_DATABASE_NAME' AND column_default IS NULL AND is_nullable = 'YES'; This will return an alter statement for every column which does not have a default value, you can copy the statements, use search and replace to remove the quotes around the strings.
🌐
Reddit
reddit.com › r/sql › how do i assign a default value to a not null column without altering a table?
r/SQL on Reddit: How do I assign a default value to a not null column without altering a table?
April 23, 2025 -

I have a table that I cannot alter, and I need to add records that don't fill out all the columns. Now, all columns in this table cannot be null. So my issue is I need to put some default data in these columns, but I can't set a default value since I cannot alter the table. For varchar fields, I was just going to put empty strings? But I also have DateTime and TimeStamp, and I don't know what to do with them.

This is for a class where they don't want you to alter the table in any way. They have a bunch of useless columns, and I won't be gathering the data. But I need to fill out all the column values to add a record, and all columns cannot be null.

🌐
DB Vis
dbvis.com › thetable › mysql-nullable-columns-everything-you-need-to-know
MySQL Nullable Columns: Everything You Need to Know
December 3, 2024 - To modify a MySQL column to allow NULL values, you can use the ALTER TABLE statement with the MODIFY keyword, followed by the column name, data type, and NULL keyword: ... Yes, a non-nullable column in MySQL can be changed to nullable using ...
🌐
Stack Exchange
dba.stackexchange.com › questions › 229558 › mysql-unable-to-drop-a-columns-null-default
Mysql: Unable to drop a columns NULL default - Database Administrators Stack Exchange
February 12, 2019 - As recommended by @danblack, SHOW CREATE should be used instead and will report accurately that the NULL defaults have been dropped. ... mysql> CREATE TEMPORARY TABLE t ( n INT NULL, nn INT NOT NULL, ndn INT NULL DEFAULT NULL, nndn INT NOT NULL DEFAULT 0 -- (does not allow DEFAULT NULL) ); mysql> DESCRIBE t; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | n | int(11) | YES | | NULL | | | nn | int(11) | NO | | NULL | | | ndn | int(11) | YES | | NULL | | | nndn | int(11) | NO | | 0 | | +-------+---------+------+-----+---------+-------+ mysql> SHOW CREATE TABLE t\G *************************** 1.