MySQL - 字段类型INT中的默认值

时间:2021-03-25 17:10:28

I have a question I'd like to help me solve, it's about the values of the data type in the fields of the database.

我有一个问题,我想帮助我解决,它是关于数据库字段中数据类型的值。

  1. It is mandatory to specify the number of characters or values that will have a field identifier id INT.
  2. 必须指定具有字段标识符id INT的字符数或值。

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

  1. What is the difference between id INT and id INT(11), It is mandatory to establish a number of values?.
  2. id INT和id INT(11)之间有什么区别,必须建立多个值?

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id(11) INT UNSIGNED NOT NULL AUTO_INCREMENT

id(11)INT UNSIGNED NOT NULL AUTO_INCREMENT

  1. What is the default setting MySQL in id INT, if not specify any value?

    如果没有指定任何值,id INT中的默认设置是什么?

  2. What is the maximum amount exact numbers that allows me to add INT

    允许我添加INT的最大确切数量是多少

  3. In that case you must use INT

    在这种情况下,您必须使用INT

  4. In that case you should use BIGINT

    在这种情况下,你应该使用BIGINT

Example: I will take an example of a news portal, that I could receive many visits.

示例:我将举一个新闻门户的例子,我可以接受很多访问。

Need to record the number of times it is accessed worldwide news, let's say your news year is visited 999.999.999 times, is a bit exaggerated know :), but it is valid to use in this case INT or BIGINT

需要记录它访问全球新闻的次数,假设你的新闻年份被访问了999.999.999次,有点夸张知道:),但在这种情况下使用INT或BIGINT是有效的

I much appreciate your support.

非常感谢您的支持。

2 个解决方案

#1


3  

According to Numeric Type Attributes:

根据数字类型属性:

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

MySQL支持扩展,可以选择在类型的base关键字后面的括号中指定整数数据类型的显示宽度。例如,INT(4)指定显示宽度为四位的INT。应用程序可以使用此可选显示宽度来显示宽度小于为列指定的宽度的整数值,方法是用空格填充它们。 (也就是说,此宽度存在于使用结果集返回的元数据中。是否使用它取决于应用程序。)

And according to Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT:

并根据整数类型(精确值) - INTEGER,INT,SMALLINT,TINYINT,MEDIUMINT,BIGINT:

The datatype INT uses 4 bytes (from -2147483648 to 2147483647 or unsigned from 0 to 4294967295), the datatype BIGINT uses 8 bytes (from -9223372036854775808 to 9223372036854775807 or unsigned from 0 to 18446744073709551615).

数据类型INT使用4个字节(从-2147483648到2147483647或从0到4294967295无符号),数据类型BIGINT使用8个字节(从-9223372036854775808到9223372036854775807或无符号从0到18446744073709551615)。

So the answers to your questions in my opinion are:

所以我认为你的问题的答案是:

  • Ad 1) No.
  • 广告1)号

  • Ad 2) The display with as described above.
  • Ad 2)具有如上所述的显示器。

  • Ad 3) No display width will be specified.
  • 广告3)不指定显示宽度。

  • Ad 4) See above.
  • 广告4)见上文。

  • Ad 5 and 6) Up to 2147483647 you can use INT, above that value you can must either use unsigned INT or BIGINT.
  • Ad 5和6)最多2147483647您可以使用INT,在该值之上,您必须使用无符号INT或BIGINT。

#2


2  

  1. It is mandatory to specify the number of characters or values that will have a field identifier id INT.
  2. 必须指定具有字段标识符id INT的字符数或值。

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

ANS: In the Database the primary key begins at one and increments by one. So 1,2, ... For this reason, you do not have to specify UNSIGNED

ANS:在数据库中,主键从1开始并递增1。所以1,2,...因此,您不必指定UNSIGNED

  1. What is the difference between id INT and id INT(11), It is mandatory to establish a number of values?.
  2. id INT和id INT(11)之间有什么区别,必须建立多个值?

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

// the (11) would be on the datatype, not the name of the column.

//(11)将是数据类型,而不是列的名称。

id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT

id INT(11)UNSIGNED NOT NULL AUTO_INCREMENT

ANS: When you specify the limit, that is the maximum number of characters it can go. The maximum for an INT is 2147483647. In an INT, the limit does not affect

ANS:指定限制时,即可以达到的最大字符数。 INT的最大值为2147483647.在INT中,限制不会影响

  1. What is the default setting MySQL in id INT, if not specify any value?
  2. 如果没有指定任何值,id INT中的默认设置是什么?

ANS: the Default for an INT is 0 unless it is a Primary Key, in which case it is a 1

ANS:INT的默认值为0,除非它是主键,在这种情况下它是1

  1. What is the maximum amount exact numbers that allows me to add INT?
  2. 允许我添加INT的最大确切数量是多少?

MySQL  - 字段类型INT中的默认值

  1. In that case you must use INT
  2. 在这种情况下,您必须使用INT

Ans: For Primary Keys or for a column in which you always want a whole number. Example: Quantity of something.

答:对于主键或您总是需要整数的列。示例:某物的数量。

  1. In that case you should use BIGINT
  2. 在这种情况下,你应该使用BIGINT

Ans:You can use BIGINT for when the number is a lot more than what an INT can hold

Ans:当数字远远超过INT可容纳的数量时,您可以使用BIGINT

You can refer to http://dev.mysql.com/doc/refman/5.7/en/integer-types.html

您可以参考http://dev.mysql.com/doc/refman/5.7/en/integer-types.html

#1


3  

According to Numeric Type Attributes:

根据数字类型属性:

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

MySQL支持扩展,可以选择在类型的base关键字后面的括号中指定整数数据类型的显示宽度。例如,INT(4)指定显示宽度为四位的INT。应用程序可以使用此可选显示宽度来显示宽度小于为列指定的宽度的整数值,方法是用空格填充它们。 (也就是说,此宽度存在于使用结果集返回的元数据中。是否使用它取决于应用程序。)

And according to Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT:

并根据整数类型(精确值) - INTEGER,INT,SMALLINT,TINYINT,MEDIUMINT,BIGINT:

The datatype INT uses 4 bytes (from -2147483648 to 2147483647 or unsigned from 0 to 4294967295), the datatype BIGINT uses 8 bytes (from -9223372036854775808 to 9223372036854775807 or unsigned from 0 to 18446744073709551615).

数据类型INT使用4个字节(从-2147483648到2147483647或从0到4294967295无符号),数据类型BIGINT使用8个字节(从-9223372036854775808到9223372036854775807或无符号从0到18446744073709551615)。

So the answers to your questions in my opinion are:

所以我认为你的问题的答案是:

  • Ad 1) No.
  • 广告1)号

  • Ad 2) The display with as described above.
  • Ad 2)具有如上所述的显示器。

  • Ad 3) No display width will be specified.
  • 广告3)不指定显示宽度。

  • Ad 4) See above.
  • 广告4)见上文。

  • Ad 5 and 6) Up to 2147483647 you can use INT, above that value you can must either use unsigned INT or BIGINT.
  • Ad 5和6)最多2147483647您可以使用INT,在该值之上,您必须使用无符号INT或BIGINT。

#2


2  

  1. It is mandatory to specify the number of characters or values that will have a field identifier id INT.
  2. 必须指定具有字段标识符id INT的字符数或值。

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

ANS: In the Database the primary key begins at one and increments by one. So 1,2, ... For this reason, you do not have to specify UNSIGNED

ANS:在数据库中,主键从1开始并递增1。所以1,2,...因此,您不必指定UNSIGNED

  1. What is the difference between id INT and id INT(11), It is mandatory to establish a number of values?.
  2. id INT和id INT(11)之间有什么区别,必须建立多个值?

id INT UNSIGNED NOT NULL AUTO_INCREMENT

id INT UNSIGNED NOT NULL AUTO_INCREMENT

// the (11) would be on the datatype, not the name of the column.

//(11)将是数据类型,而不是列的名称。

id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT

id INT(11)UNSIGNED NOT NULL AUTO_INCREMENT

ANS: When you specify the limit, that is the maximum number of characters it can go. The maximum for an INT is 2147483647. In an INT, the limit does not affect

ANS:指定限制时,即可以达到的最大字符数。 INT的最大值为2147483647.在INT中,限制不会影响

  1. What is the default setting MySQL in id INT, if not specify any value?
  2. 如果没有指定任何值,id INT中的默认设置是什么?

ANS: the Default for an INT is 0 unless it is a Primary Key, in which case it is a 1

ANS:INT的默认值为0,除非它是主键,在这种情况下它是1

  1. What is the maximum amount exact numbers that allows me to add INT?
  2. 允许我添加INT的最大确切数量是多少?

MySQL  - 字段类型INT中的默认值

  1. In that case you must use INT
  2. 在这种情况下,您必须使用INT

Ans: For Primary Keys or for a column in which you always want a whole number. Example: Quantity of something.

答:对于主键或您总是需要整数的列。示例:某物的数量。

  1. In that case you should use BIGINT
  2. 在这种情况下,你应该使用BIGINT

Ans:You can use BIGINT for when the number is a lot more than what an INT can hold

Ans:当数字远远超过INT可容纳的数量时,您可以使用BIGINT

You can refer to http://dev.mysql.com/doc/refman/5.7/en/integer-types.html

您可以参考http://dev.mysql.com/doc/refman/5.7/en/integer-types.html