Home Database Mysql Tutorial 数据库设计字段类型设置经验

数据库设计字段类型设置经验

Jun 07, 2016 pm 03:00 PM
Field develop database type experience set up design past

将过去在开发中体会到经验整理出来。今天贴出来,整理,做个备忘。 tinyint 是-128到128 。当属性设置为unsigned的时候。最大值就是255了。现在知道为什么需要设置为unsigned属性了。原来是为了最大限度的使用给予的存储空间。如果不设置。那么假如你的值都

将过去在开发中体会到经验整理出来。今天贴出来,整理,做个备忘。

 

 

 

tinyint 是-128到128 。当属性设置为unsigned的时候。最大值就是255了。现在知道为什么需要设置为unsigned属性了。原来是为了最大限度的使用给予的存储空间。如果不设置。那么假如你的值都是正数的。那么-128这一百多个数字就相当于是浪费了。
tinyint会自动设置为tinyint(3)
smallint  不设置unsigned的时候,也有3万多的样子。


tinytext 就是255个字节。大概就是存储127个中文的样子 tinytext就相当于varchar类型。把它看成这样的该类型就容易理解了。

int 类型phpmyadmin默认会设置int(10)

概念纠正:原来一直以为这里的10表示位数。直到有次想保存1101061021496,结果在字段中的值都变成了:4294967295。 看MySQL手册上说:

(int后面括号的数字)显示宽度并不限制可以在列内保存的值的范围,也不限制超过列的指定宽度的值的显示。
int的范围:-2147483648到2147483647。刚好是10个位,那么就是数十亿级别的数字。数据库设计经验:像订单的值非常大。不确定,如果达到10位数,还不如使用varchar类型。fangwei就没有使用int,而是varchar类型



从上面也告诉我一个经验:如果保存在数据库的值都变成一样的。也就是无论我是1101061021496 还是1101061021569,结果都变成了固定的值,比如4294967295。那么可以考虑确认是否是数据库该字段的范围问题。这样的问题出现过好几次了。就是没有掌握思路。导致浪费了不少时间。



将字段设置为not null 还出于另外一种考虑:mysql表的列中包含null的话,那么该列不会包含在所有中。也就是使用索引是无效的。所有,考虑今后会使用索引的字段,就要设置字段属性是not null。
如果你要保存NULL,手动去设置它,而不是把它设为默认值。



考虑到这个字段今后会作为查询关键字使用like的形式进行搜索。那么要将该字段定义成索引。这样使用like查询就会更快。
现在终于体会到到国外作者书籍上提到:设计数据库之前要问自己,之后会查询哪些数据。  考虑了这些,以后有什么查询需要。结构都能适应了。


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

2011.1.19 关于设计大流量网站数据库,会员分表或者分库的设计考虑:

主键不要设为自增型。设置为自增型的后果就是:今后无法分离在不同的mysql数据库服务器上。比如id编号由于是自增的,所以两个数据库中可能会出现用户编号都是10005的情况。

但是,mysql主键会自动设置为自增型。可以用另外一个字段来作为标识符。而不是自增型id号。方法:新增一个字段作为行的标识符。具体设计:一个表做两个字段,一个是id作为主键,自增型,另外一个是uid,作为用户的标识。

程序判断上,是以uid作为判断用户的依据。而不是id主键作为判断依据(程序上的失误,改动比起数据库设计失误改动容易得多。因为你数据已经入库了。在修改起来就比较难了)
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Jul 18, 2024 am 09:27 AM

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of ​​​​sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

New stacking process! Xiaomi MIX Fold 4 is equipped with Jinshajiang 'three-dimensional special-shaped' battery for the first time New stacking process! Xiaomi MIX Fold 4 is equipped with Jinshajiang 'three-dimensional special-shaped' battery for the first time Jul 20, 2024 am 03:20 AM

According to news on July 19, Xiaomi MIX Fold 4, the first flagship folding new phone, was officially released tonight and is equipped with a "three-dimensional special-shaped battery" for the first time. According to reports, Xiaomi MIX Fold4 has achieved a major breakthrough in battery technology and designed an innovative "three-dimensional special-shaped battery" specifically for folding screens. Traditional folding screen devices mostly use conventional square batteries, which have low space utilization efficiency. In order to solve this problem, Xiaomi did not use the common winding battery cells, but developed a new lamination process to create a new form of battery, which greatly improved the space utilization. Battery Technology Innovation In order to accurately alternately stack positive and negative electrode sheets and ensure the safe embedding of lithium ions, Xiaomi has developed a new ultrasonic welding machine and lamination machine to improve welding and cutting accuracy.

The 2024 Apple iPad Pro/Air does not support the second-generation Apple Pencil: you can buy a new one if you need it The 2024 Apple iPad Pro/Air does not support the second-generation Apple Pencil: you can buy a new one if you need it May 08, 2024 pm 04:07 PM

According to news on May 8, Apple’s new iPad Pro/Air tablets have been released. According to Apple’s official website, the new iPad Pro and iPad Air no longer support the second-generation Apple Pencil released in 2018, but only support Apple Pencil Pro and Apple Pencil (USB- C). Apple Pencil (USB-C) will be released in November 2023. This stylus maintains the same pixel-level accuracy, low latency, and tilt-angle sensing features as the first and second-generation Apple Pencil, while eliminating pressure sensitivity. function and does not support wireless charging. Its price is 649 yuan. And the newly released ApplePe

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Honor X60i mobile phone is on sale starting from 1,399 yuan: visual quadrilateral OLED direct screen Honor X60i mobile phone is on sale starting from 1,399 yuan: visual quadrilateral OLED direct screen Jul 29, 2024 pm 08:25 PM

According to news on July 29, the Honor X60i mobile phone is officially on sale today, starting at 1,399 yuan. In terms of design, the Honor X60i mobile phone adopts a straight screen design with a hole in the center and almost unbounded ultra-narrow borders on all four sides, which greatly broadens the field of view. Honor X60i parameters Display: 6.7-inch high-definition display Battery: 5000mAh large-capacity battery Processor: Dimensity 6080 processor (TSMC 6nm, 2x2.4G A76+6×2G A55) System: MagicOS8.0 system Other features: 5G signal enhancement, smart capsule, under-screen fingerprint, dual MIC, noise reduction, knowledge Q&A, photography capabilities: rear dual camera system: 50 million pixels main camera, 2 million pixels auxiliary lens, front selfie lens: 8 million pixels, price: 8GB

Vivo's phone with the strongest signal! vivo X100s is equipped with a universal signal amplification system: 21 antennas, 360° surround design Vivo's phone with the strongest signal! vivo X100s is equipped with a universal signal amplification system: 21 antennas, 360° surround design Jun 03, 2024 pm 08:41 PM

According to news on May 13, vivoX100s was officially released tonight. In addition to excellent images, the new phone also performs very well in terms of signal. According to vivo’s official introduction, vivoX100s uses an innovative universal signal amplification system, which is equipped with up to 21 antennas. This design has been re-optimized based on the direct screen to balance many signal requirements such as 5G, 4G, Wi-Fi, GPS, and NFC. This makes vivoX100s the mobile phone with the strongest signal reception capability in vivo’s history. The new phone also uses a unique 360° surround design, with antennas distributed around the body. This design not only enhances the signal strength, but also optimizes various daily holding postures to avoid problems caused by improper holding methods.

OnePlus Ace 3 Pro debuts second-generation Tiangong cooling system: supercritical thermal graphite OnePlus Ace 3 Pro debuts second-generation Tiangong cooling system: supercritical thermal graphite Jun 28, 2024 am 01:49 AM

According to news on June 27, OnePlus Ace3Pro will be officially released tonight. In addition to being equipped with the third-generation Snapdragon 8 flagship core, the new phone also puts great effort into heat dissipation. According to reports, OnePlus Ace3 Pro has introduced the second-generation Tiangong cooling system for the first time. This system is equipped with a 9126mm² 10,000-grade VC heat sink. Compared with the previous generation, the heat dissipation efficiency has increased by an astonishing 36%. This breakthrough technology enables mobile phones to quickly dissipate heat when running under high load, ensuring stable performance of mobile phones. What’s even more striking is that OnePlus Ace3Pro uses 2K supercritical thermal graphite for the first time: its thermal conductivity is as high as 2041W/(m·K), ranking first in the industry. The heat dissipation capacity is increased by 70%, enhancing the heat dissipation of mobile phones and maintaining stable operating temperature. scattered

See all articles