Home > Software engineering >  Why default INT(11)
Why default INT(11)

Time:11-06

In using SequelPro it uses a default INT length (for display!) of 11 when creating a table. For example:

CREATE TABLE `tbl` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

My question is why does it do that, if the (11) is only used for display purposes if zerofill is enabled, which seems like such an odd property to have on by default and it's meaningless without it.

Update: Yes, I know that the (11) is the display width and does not change the byte-size of INT which is 4 in mysql. My question is why it uses the (11) AS A DEFAULT for the display-width-when-using-zero-fill in the application? I know writing all these caps is obnoxious, but no one seems to read the full question (there are 5 answers/comments that all say the same thing).

CodePudding user response:

The number in the parenthesis i.e () does not determines the max and min values that can be stored in the integer field. The max and min values that can be stored are always fixed. It is just display width of integer data type.

CodePudding user response:

MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINT, MEDIUMINT, and BIGINT. The following table shows the required storage and range for each integer type. MySQL Int types

  • Related