Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In mysql if column datatype is integer, would it allow to store long value in int data type column?

Tags:

mysql

Suppose i want to store long value in int data type column, it would allow me to store it?

like image 963
user2119404 Avatar asked Nov 16 '25 07:11

user2119404


1 Answers

As documented under Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT:

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.

+-----------+---------+----------------------+----------------------+
|   Type    | Storage |    Minimum Value     |    Maximum Value     |
|           | (Bytes) |  (Signed/Unsigned)   |  (Signed/Unsigned)   |
+-----------+---------+----------------------+----------------------+
| TINYINT   | 1       | -128                 | 127                  |
|           |         | 0                    | 255                  |
+-----------+---------+----------------------+----------------------+
| SMALLINT  | 2       | -32768               | 32767                |
|           |         | 0                    | 65535                |
+-----------+---------+----------------------+----------------------+
| MEDIUMINT | 3       | -8388608             | 8388607              |
|           |         | 0                    | 16777215             |
+-----------+---------+----------------------+----------------------+
| INT       | 4       | -2147483648          | 2147483647           |
|           |         | 0                    | 4294967295           |
+-----------+---------+----------------------+----------------------+
| BIGINT    | 8       | -9223372036854775808 | 9223372036854775807  |
|           |         | 0                    | 18446744073709551615 |
+-----------+---------+----------------------+----------------------+

The data type required for a "long" value will depend on the language and architecture for which you define "long". In some common cases, it means a 4-byte integer (INT in MySQL) whilst in other common cases it means an 8-byte integer (BIGINT in MySQL); in less common cases, it could mean a different width entirely.

like image 87
eggyal Avatar answered Nov 17 '25 21:11

eggyal