My MySQL learning Experience (ii) data type width

Source: Internet
Author: User
Tags numeric value

Display width

The integer data type in MySQL can specify the display width, and SQL Server does not

Create a table

CREATE TABLE tb_emp (id BIGINT (1))

The ID field has a data type of bigint (1), noting the subsequent number 1, which represents the display width specified by the data type, specifying the number of digits in the numeric value that can be displayed.

For example, suppose you declare a field of type int of year int (4)

The declaration indicates that the data in the year field generally shows only the width of a 4-digit number.

It's going to be an error in SQL Server.

CREATE TABLE ABC (ID INT (11))
Msg 2716, Level 16, State 1, 1th row 1th column, parameter, or variable: column widths cannot be specified for data type int.

The display width and the value range of the data type are irrelevant. Display width only indicates the maximum number of digits that can be displayed by MySQL, and a space padding when the number of digits is less than the specified width

If a value greater than the display width is inserted, the value can be inserted and displayed as long as it does not exceed the range of values for that type of integer.

For example, to insert a numeric value of 19999 into the year field, when using a select query, MySQL will display a full 5-digit 19999 instead of a 4-bit number

If you do not specify a display width, mysql specifies a default width value for each type

Tips: The display width is for display only, and cannot limit the range and footprint, for example: Int (3) consumes 4 bytes of storage, and the maximum allowable value is not 999, but int integer

The maximum allowable value.

My MySQL learning Experience (ii) data type width

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.