Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default values for varchar and int mysql data types

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

like image 273
Igor Parra Avatar asked May 15 '12 16:05

Igor Parra


People also ask

What is the default value of varchar in MySQL?

A DEFAULT value clause in a data type specification explicitly indicates a default value for a column. Examples: CREATE TABLE t1 ( i INT DEFAULT -1, c VARCHAR(10) DEFAULT '', price DOUBLE(16,2) DEFAULT 0.00 ); SERIAL DEFAULT VALUE is a special case.

What is the default format of data in MySQL?

MySQL defaults to displaying columns of type DATETIME using the format yyyy-MM-dd HH:mm:ss .

What is the default value of integer data type?

The default value of Integer is 0.


1 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.

like image 161
None Avatar answered Oct 20 '22 09:10

None