Home Database Mysql Tutorial What is the long integer type of mysql?

What is the long integer type of mysql?

Jun 14, 2022 pm 04:40 PM
mysql

The long integer type of mysql is "BIGINT". BIGINT is an ab byte or 64-bit integer value, very useful when storing extremely large integer values. BIGINT, like other integer data types, can be signed or unsigned; the signed data type means that the column can store positive and negative integer values, while the unsigned data type means that the column can only store positive integer values. The range of signed BIGINT types is between "-9223372036854775808" and "9223372036854775807".

What is the long integer type of mysql?

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Integer type is also called numerical data. Numeric data type is mainly used to store numbers.

MySQL provides a variety of numeric data types. Different data types provide different value ranges. The larger the value range that can be stored, the greater the storage space required.

The main integer types provided by MySQL are TINYINT, SMALLINT, MEDIUMINT, INT, and BIGINT, and AUTO_INCREMENT auto-increment constraints can be added to their attribute fields. The following table lists the numeric types in MySQL.

##

As can be seen from the above table, the number of bytes required for different types of integer storage is different. The smallest number of bytes is the TINYINT type, and the largest number is the BIGINT type. The more bytes it occupies. The larger the range of values ​​that the type can represent. Therefore, the long integer type of mysql is "BIGINT".

MySQL BIGINT

BIGINT is an ab bytes or 64-bit integer value, useful when storing large integer values.

MySQL BIGINT, like any other MySQL integer data type, can be signed or unsigned. A signed data type means that the column can store both positive and negative integer values. This is the default type for most integer types in MySQL. Therefore, any integer type column can store both positive and negative integers unless explicitly specified.

On the other hand, the unsigned data type means that the column can only store positive integer values.

The range of the signed MySQL BIGINT type is between -9223372036854775808 and 9223372036854775807

For the unsigned BIGINT type, the value range is 0 to 18446744073709551615.

Another property of the BIGINT type is ZEROFILL. When this property is specified on a column, the column is automatically set to UNSIGNED.

The zerofill attribute also fills spaces with zeros.

BIGINT Examples:

Let’s look at a few examples to illustrate how to use the BIGINT type.

CREATE DATABASE IF NOT EXISTS integers;
USE integers;
Copy after login

Next, let’s create a table and populate it with various BIGINT columns as shown in the following query:

CREATE TABLE examples(x BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, y BIGINT UNSIGNED, z BIGINT ZEROFILL );
Copy after login

Example 1

Let us first try to add all positive values ​​to the table:

INSERT INTO examples(x,y,z) VALUES (1,2,3);
Copy after login

In the above example query, these values ​​are acceptable because they are in the range of signed, unsigned, and zerofill BIGINT types.

SELECT * FROM examples;
Copy after login
Copy after login

What is the long integer type of mysql?

Example 2

In the next case, let's try adding all negative values. An example query is as follows:

INSERT INTO examples(x,y,z) VALUES (-1,-2,-3);
ERROR 1264 (22003): Out of range value for column 'y' at row 1
Copy after login

In this case, the query fails because the y column is unsigned. Therefore, assigning a negative value to a column is outside the column range.

Example 3

We can observe that the same as above Similar situation in the third column. The zerofill attribute automatically makes the column unsigned, making adding negative values ​​out of range. An example is:

INSERT INTO examples(x,y,z) VALUES (-1,2,-3);
ERROR 1264 (22003): Out of range value for column 'z' at row 1
Copy after login

Example 4

Now Let's try adding the maximum value of each type. An example query is:

INSERT INTO examples(x,y,z) VALUES (-9223372036854775808, 9223372036854775808, 9223372036854775808);
Copy after login

In the above example, the query executes successfully since all the values ​​are within the range.

Consider the following query:

INSERT INTO examples(x,y,z) VALUES (9223372036854775807, 9223372036854775808, 9223372036854775808);
Copy after login

You will notice that all the values ​​are on the maximum value. Since column x is set to AUTO_INCREMENT, adding a value to it will fail.

INSERT INTO examples(y,z) VALUES (9223372036854775808, 9223372036854775808);
ERROR 1062 (23000): Duplicate entry '9223372036854775807' for key 'examples.PRIMARY'
Copy after login

However, if strict mode is disabled in MySQL, you can insert out-of-range values.

SELECT * FROM examples;
Copy after login
Copy after login

What is the long integer type of mysql?[Related recommendations:

mysql video tutorial

]

Type Size Range (signed) Range (unsigned) Purpose
TINYINT 1 byte (-128,127) (0,255) Small integer value
SMALLINT 2 bytes (-32 768, 32 767) (0, 65 535) Large integer value
MEDIUMINT 3 bytes (-8 388 608, 8 388 607) (0,16 777 215) Large integer value
INT or INTEGER 4 words Section (-2 147 483 648, 2 147 483 647) (0, 4 294 967 295) Large integer value
BIGINT 8 bytes (-9,223,372,036,854,775,808, 9 223 372 036 854 775 807) (0, 18 446 744 073 709 551 615) Great integer value

The above is the detailed content of What is the long integer type of mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

See all articles