Home  >  Article  >  Database  >  MySQL uses one statement to find out the number of bytes occupied by various integers and the maximum and minimum values.

MySQL uses one statement to find out the number of bytes occupied by various integers and the maximum and minimum values.

黄舟
黄舟Original
2017-03-21 13:26:091160browse

The following editor will bring you an articleMySQLAn example of finding out the number of bytes occupied by various integers and the maximum and minimum values ​​using one statement.

Directly code:

select 'bigint unsigned' as type ,'8' as bytes ,~0 as max_num,0 as min_num union
select 'int unsigned','4',~0>>32,0 union
select 'mediumint unsigned','3',~0>>40,0 union
select 'smallint unsigned','2',~0>>48,0 union
select 'tinyint unsigned','1',~0>>56,0 union
select &#39;signed bigint&#39;,&#39;8&#39;,~0>>1,-(1<<63) union
select &#39;signed int&#39;,&#39;4&#39;,~0>>33,-(1<<31) union
select &#39;signed mediumint&#39;,&#39;3&#39;,~0>>41,-(1<<23) union
select &#39;signed smallint&#39;,&#39;2&#39;,~0>>49,-(1<<15) union
select &#39;signed tinyint&#39;,&#39;1&#39;,~0>>57,-(1<<7);

+--------------------+-------+----------------------+----------------------+
| type    | bytes | max_num    | min_num    |
+--------------------+-------+----------------------+----------------------+
| bigint unsigned | 8  | 18446744073709551615 |     0 |
| int unsigned  | 4  |   4294967295 |     0 |
| mediumint unsigned | 3  |    16777215 |     0 |
| smallint unsigned | 2  |    65535 |     0 |
| tinyint unsigned | 1  |     255 |     0 |
| signed bigint  | 8  | 9223372036854775807 | -9223372036854775808 |
| signed int   | 4  |   2147483647 |   -2147483648 |
| signed mediumint | 3  |    8388607 |    -8388608 |
| signed smallint | 2  |    32767 |    -32768 |
| signed tinyint  | 1  |     127 |     -128 |
+--------------------+-------+----------------------+----------------------+
rows in set (0.00 sec)

The above is the detailed content of MySQL uses one statement to find out the number of bytes occupied by various integers and the maximum and minimum values.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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