SQL数据库一般设计原则(一)
要开发一个基于数据库的应用系统,其中最关键的一步就是整个系统所依据的数据库的建模设计,从逻辑的到物理的,一个环节疏于设计,整个的应用系统便建立在危房之上,随着开发过程的不断深入,它要随时面临着各种难以预料的风险,开发者要为修改或重新设计没
要开发一个基于数据库的应用系统,其中最关键的一步就是整个系统所依据的数据库的建模设计,从逻辑的到物理的,一个环节疏于设计,整个的应用系统便似建立在危房之上,随着开发过程的不断深入,它要随时面临着各种难以预料的风险,开发者要为修改或重新设计没有设计好的数据库系统而付出难以预料的代价。所以,一个好的数据库设计原则是高效率的系统所必须的。
一、数据库设计原则之逻辑建模
可以用一些通用的工具来进行,如Rational rose,PowerDesigner等,这一阶段主要是依据系统的需求,获取与分析要实现的应用系统信息,进行数据内部以及外在关系的分析,从而有效地建立整个系统的数据结构(在关系数据库中通常称为表结构),在此基础上对数据库的数据量、数据流量、及响应速度的估算分析,这样数据模型就产生了。
具体的操作准则是数据库的几个范式、用户的具体需求和分析者的经验,从数据库的性能、安全、方便管理、易于开发等方面出发,具体方法因分析员的喜好和习惯而异,可以不用工具,最好使用工具,能让分析过程简便,最主要是能生成一些图,如E-R图,让分析过程一目了然。
鉴于我是走的.NET路子,一般在此阶段我采取的是首先根据实际需求判断出数据库中应该有哪些实体对象,比如Student、Course等,然后考虑哪些实体它们之间会有关联,然后再会用PowerDesigner很方便地建一个逻辑模型LDM,把我的思路呈现出来,把表和表之间的联系建好。这一步就大致弄好了。
二、数据库设计原则之物理设计
物理设计可以简单地认为是如何尽量合理地给数据库分配物理空间,这一步在数据库设计中很重要,关系到数据库数据的安全和数据库的性能。一般这个时候就会考虑每个实体的属性,把逻辑模型升级为物理模型。
这阶段主要干的事就是仔细考量每一个属性的取值范围,为它选一个合适的数据类型。一般而言在这阶段的原则就是最大限度地减少数据库所占用的存储空间,例如性别考虑用int乃至tingint,一些经常出现的常量比如“有效”、“注销”也统统用tingint代表。另外,这里的命名也要规范,数据库里相同的字段名称、数据类型都要统一。
三、数据库设计原则之键的设计
主键:一般不建议使用自增长,自增长虽然节省时间,不用考虑,写程序也简单了,因为数据库帮我们维护着这一批ID号。但是, 如果后面需要升级为做分布式数据库时,要求数据同步时,这种自增ID就会出现严重的问题,因为你无法用该ID来唯一标识记录。同时在数据库做移植时,也会出现各种问题,总之,对此自增ID有依赖的情况,都有可能出现问题。推荐使用uniqueidentifier类型,也就是C#里的GUID。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



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.

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

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

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.

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.

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

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())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.
