Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1653505
  • 博文数量: 135
  • 博客积分: 2820
  • 博客等级: 少校
  • 技术积分: 2544
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-16 13:33
文章分类

全部博文(135)

文章存档

2015年(1)

2014年(8)

2013年(16)

2012年(43)

2011年(56)

2010年(11)

分类: Mysql/postgreSQL

2013-04-17 15:58:57

20 个数据库设计最佳实践
1. 使用明确、统一的标明和列名,例如 School, SchoolCourse, CourceID。
2. 数据表名使用单数而不是复数,例如 StudentCourse,而不是StudentCourses。
3. 数据表名不要使用空格。
4. 数据表名不要使用不必要的前缀或者后缀,例如使用School,而不是TblSchool,或者SchoolTable等等。
5. 数据库中的密码要加密,到应用中再解密。 (其实就是散列存储、单向加密)
6. 使用整数作为ID字段,也许现在没有这个必要,但是将来需要,例如关联表,索引等等。
7. 使用整数字段做索引,否则会带来很大的性能问题 。
8. 使用 bit 作为布尔字段,使用整数或者varcha是浪费。同时,这类字段应该以“Is”开头。
9. 要经过认证才能访问数据库,不要给每一个用户管理员权限。
10. 尽量避免使用“select *”,而使用“select [required_column_list]”以获得更好的性能。
11. 假如程序代码比较复杂,使用ORM框架,例如hibernate,iBatis。ORM框架的性能问题可以通过详细的配置去解决。
12. 分割不常使用的数据表到不同的物理存储以获得更好的性能。
13. 对于关键数据库,使用安全备份系统,例如集群,同步等等。
14. 使用外键,非空等限制来保证数据的完整性,不要把所有的东西都扔给程序。
15. 缺乏数据库文档是致命的。你应该为你的数据库设计写文档,包括触发器、存储过程和其他脚本。
16. 对于经常使用的查询和大型数据表,要使用索引。数据分析工具可以帮助你决定如何建立索引。
17. 数据库服务器和网页服务器应该放在不同的机器上。这回提高安全性,并减轻CPU压力。
18. Image和blob字段不应该定义在常用的数据表中,否则会影响性能。
19. 范式(Normalization)要按照要求使用以提高性能。Normalization做的不够会导致数据冗余,而过度Normalization 会导致太多的join和数据表,这两种情况都会影响性能。
20. 多花点时间在数据库设计上,否则你将来会付出加倍的时间来偿还。

1. Use well defined and consistent names for tables and columns (e.g. School, StudentCourse, CourseID …).
2. Use singular for table names (i.e. use StudentCourse instead of StudentCourses). Table represents a collection of entities, there is no need for plural names.
3. Don’t use spaces for table names. Otherwise you will have to use ‘{‘, ‘[‘, ‘“’ etc. characters to define tables (i.e. for accesing table Student Course you'll write “Student Course”. StudentCourse is much better).
4. Don’t use unnecessary prefixes or suffixes for table names (i.e. use School instead of TblSchool, SchoolTable etc.).
5. Keep passwords as encrypted for security. Decrypt them in application when required.
6. Use integer id fields for all tables. If id is not required for the time being, it may be required in the future (for association tables, indexing ...).
7. Choose columns with the integer data type (or its variants) for indexing. varchar column indexing will cause performance problems.
8. Use bit fields for boolean values. Using integer or varchar is unnecessarily storage consuming. Also start those column names with “Is”.
9. Provide authentication for database access. Don’t give admin role to each user.
10. Avoid “select *” queries until it is really needed. Use "select [required_columns_list]” for better performance.
11. Use an ORM (object relational mapping) framework (i.e. hibernate, iBatis …) if application code is big enough. Performance issues of ORM frameworks can be handled by detailed configuration parameters.
12. Partition big and unused/rarely used tables/table parts to different physical storages for better query performance.
13. For big, sensitive and mission critic database systems, use disaster recovery and security services like failover clustering, auto backups, replication etc.
14. Use constraints (foreign key, check, not null …) for data integrity. Don’t give whole control to application code.
15. Lack of database documentation is evil. Document your database design with ER schemas and instructions. Also write comment lines for your triggers, stored procedures and other scripts.
16. Use indexes for frequently used queries on big tables. Analyser tools can be used to determine where indexes will be defined. For queries retrieving a range of rows, clustered indexes are usually better. For point queries, non-clustered indexes are usually better.
17. Database server and the web server must be placed in different machines. This will provide more security (attackers can’t access data directly) and server CPU and memory performance will be better because of reduced request number and process usage.
18. Image and blob data columns must not be defined in frequently queried tables because of performance issues. These data must be placed in separate tables and their pointer can be used in queried tables.
19. Normalization must be used as required, to optimize the performance. Under-normalization will cause excessive repetition of data, over-normalization will cause excessive joins across too many tables. Both of them will get worse performance.
20. Spend time for database modeling and design as much as required. Otherwise saved(!) design time will cause (saved(!) design time) * 10/100/1000 maintenance and re-design time.

阅读(1955) | 评论(0) | 转发(0) |
0

上一篇:Cisco3750基本配置

下一篇:python 八荣八耻

给主人留下些什么吧!~~