Comparison with MSSQL to learn about MYSQL (2) -- display width _ MySQL

Source: Internet
Author: User
Comparison with MSSQL to learn about MYSQL (2) -- display width: Let's first look at the width range of integer data types

Create a table


Create table tb_emp (id BIGINT (1 ))

The data type of the id field is BIGINT (1). Note the following number 1, which indicates the display width specified by the data type and the number of digits that can be displayed.

For example, assume that the year int (4) field of the INT type is declared)

This statement indicates that data in the year field usually only shows the width of four digits.

An error is reported in SQLSERVER.


Create table abc
(Id INT (11 ))


Message 2716, level 16, state 1, 1st rows
1st columns, parameters, or variables: the column width cannot be specified for the data type int.

The display width is irrelevant to the value range of the data type. The display width only specifies the maximum number of digits that MYSQL may display. if the number of digits is smaller than the specified width, a space is entered.

If you insert a value greater than the display width, as long as the value does not exceed the value range of this type of integer, the value can still be inserted and displayed.

For example, if you insert a value of 19999 into the year field and use the select statement to query data, MYSQL displays a full value of 19999 with five digits instead of a four-digit value.

If the display width is not specified, MYSQL specifies the default width for each type.

Tips: The display width is only used for display, and the value range and occupied space cannot be limited. for example, INT (3) occupies 4 bytes of storage space, in addition, the maximum value is not 999, but the maximum value allowed by the INT type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.