在设计数据库的时候,整数类型的使用时不可避免的如ID,类型等。
在选择整数的同时主要是考虑是数据范围,如是否带符号,最大存储值。
一、有误符号
在无符号unsigned类型比有符号的整数多一倍。
如
tinyint 范围 -128~127
tinyint unsigned 范围 0~255
这里的tinyint unsigned比tinyint 最大数多一倍,其它的同理。
如
果我们的范围 1-200,如果使用带符号的整数 tinyint是不能满足的,使用只有选择更宽的字段但使用tinyint unsigned就可以满足。
二、整数范围
tinyint ~百
smallint ~万
mediumint ~千万
int ~10亿
bigint ~ 10亿x10亿
数据详情范围
tinyint 8 bits 0 ~ 255 -128 ~ 127smallint 16 bits 0 ~ 65535 -32768 ~ 32767
mediumint 24 bits 0 ~ 16777216 -8388608 ~ 8388607
int 32 bits 0 ~ 4294967295 -2147483648 ~ 2147483647
bigint 64 bits 0 ~ 18446744073709551615 -9223372036854775808 ~ 9223372036854775807
三、如何选择
这里的数据主要是大楷的数据范围比如100左右用tinyint ,有时我们需要通过计算,比如我们发布的一片新闻
统计它的访问量,如:1000(日访问量)*365(天)*10(年)=36500000(千万) 这是数据是大于mediumint,而在int范围类
但如果我们考虑一下,一篇新闻能到日访问量到1000而且持续10年,如果能那就选择int,如果可能性不大mediumint可能是最好的选择。
有时我们都图略的这些范围的分析,反正只要是整数,要么int或者bigint。在不是很影响性能的情况下,节约设计分析。
当时还有一个设计误区其实用 int(x)来作为整数范围,原来发布过相应的博客数据库-整数类型宽度—int(3)与int(11)区别 来论证过!
原文地址: http://blog.yi18.net/articles/2014/04/06/1396777140197.html
This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
