search
HomeDatabaseMysql Tutorial数据库设计的最佳实践

数据库设计的最佳实践

Jun 07, 2016 pm 02:58 PM
usepracticedatabaseoptimaldesign

数据库设计的最佳实践 1、使用定义明确的表或列名,并保持一致(例如,School、StudentCourse、CourseID)。 2、使用单数形式的表名(即,用StudentCourse而非StudentCourses)。表代表了实体的合集,不需要复数形式。 3、不要在表名中使用空格。否则你将在

数据库设计的最佳实践

 

1、使用定义明确的表或列名,并保持一致(例如,School、StudentCourse、CourseID)。

 

2、使用单数形式的表名(即,用StudentCourse而非StudentCourses)。表代表了实体的合集,不需要复数形式。

 

3、不要在表名中使用空格。否则你将在定义表时不得不使用“{”、“[”等字符(即为了访问表Student Course,你须得书写“Student Course”。使用StudentCourse足够了)。

 

4、不要在表名中加入不必要的前缀或后缀(即,命名School即可,不必为TblSchool、SchoolTable等)。

 

5、加密密码,保证安全性。需要时可在应用中解密它们。

 

6、在所有的表中使用整型ID字段。即便眼下ID还用不着,将来也会有用到的时候(例如在关联表中、索引等)。

 

7、使用整数(或相关)类型的数据列来创建索引。Varchar列索引会导致性能问题。

 

8、对布尔值使用bit字段。使用Integer或Varchar类型存储毫无必要。同时,在这些列名中加入Is描述。

 

9、对数据库访问进行验证。任何用户都不应给予admin角色。

 

10、若非必要的话,避免使用“select *”查询语句。为了更好的性能,请使用“select [required_columns_list]”。

 

11、若程序代码很大,可使用ORM(对象关系映射)框架(如Hibernate、iBatis)工具。关于其性能问题可通过详细配置参数来应付。

 

12、将那些不使用或不常用而又较大的表(table parts)区隔到不同的物理存储空间,以便提供更好地查询性能。

 

13、对重要的数据库系统,使用灾难恢复方案和安全服务,比如故障切换集群(failover clustering)、自动备份、复制等。

 

14、为了保证数据完整性,请使用约束(如外键、Check、Not null约束等)。不要给予对应用代码的完整控制权。

 

15、缺乏数据库文档的习惯非常不好(evil)。用ER图对数据库设计模型进行描述。同时记得编写触发器、存储过程等脚本的代码。

 

16、对频繁进行的查询使用索引。Analyser工具可用于决定index在何处定义。对于查询获取大量列,聚簇索引(clustered index)通常更好。而对于点查询,可使用非聚簇索引。

 

17、将数据库服务器与Web服务器放置在不同的计算机中。这可以提供更好的安全性能(攻击者不能直接访问数据),而且由于可以限制访问请求数及进程量,服务器也能获得更的CPU及内存性能。

 

18、图像和Blob列一定不要定义在查询频繁的表中,这也是出于性能考虑。可将这些数据放在单独的表中,并在查询表中建立指向它们的指针。

 

19、规范化(Normalization)是必须的,以进一步优化应用性能。否则可能面临过多的数据副本,当然过渡规范化(over-normalization)则会导致大量跨太多表的连接。这两者都会影响到性能。

 

20、同样也要在数据库建模及设计上花些功夫。若为此省下时间,则很可能面临10倍乃至100/1000倍的维护/重新设计成本。

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
MySQL String Types: Storage, Performance, and Best PracticesMySQL String Types: Storage, Performance, and Best PracticesMay 10, 2025 am 12:02 AM

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

Understanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreUnderstanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreMay 10, 2025 am 12:02 AM

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

What are the String Data Types in MySQL?What are the String Data Types in MySQL?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.