Home » Php » php – Default values for varchar and int mysql data types

php – Default values for varchar and int mysql data types

Posted by: admin July 12, 2020 Leave a comment

Questions:

The screenshot show 3 typical definitions of data type: id (autoincrement), a title and a number.

1.- Which are differences between: none and NULL?
2.- Do I must choose as defined: '' for varchar types when I want an empty string?
3.- Do I must put an as defined: 0 default value for autoincrement int types?

enter image description here

How to&Answers:

Default none means there is no default value. If a value is not provided on an insert, the query will fail with a “no default value error”.

NULL is the actual NULL value meaning if no value is provided on an insert the column will default to NULL (empty). For varchar you can set default to ”, but NULL is better.

Autoincrement int types shouldn’t have a default value (Default: None) because it will always have a value.