Difference between NULL DEFAULT NULL and DEFAULT NULL in MySQL?

I recently ran into a new problem in MySQL. I was going to create a new table with

col1 TIMESTAMP DEFAULT NULL

(i.e. a column that has a default NULL value), but on creation, which gave me an error:

Invalid default value for column

But when I tried col1 TIMESTAMP NULL DEFAULT NULL , this table was created.

I want to know what is the difference between the two above syntaxes. I also came across this problem earlier and in some inserted NULL values ​​in a column.

Can someone explain the cause of this problem, for example, is it a specific version problem or something else with MySQL?

+7
source share
1 answer

The first NULL says that the column is nullified, that is, it accepts NULL . The second NULL (after DEFAULT ) is the default value.

If you only have a default value, but the column is rejected by empty values, then this default value cannot be used.

(However, I got the impression that if you specify either NULL or NOT NULL , the column will be nullable, so what you see is a little confusing).

+10
source

Source: https://habr.com/ru/post/924992/


All Articles