Database Design Guidelines

Principles

  • Support popular databases

Name Style

  • Table Name

    Style: Pascal

    Example: Employee

    It is fine that you may use the singular style or plural style. But singular style is preferred here.

  • Column Name

    Style: Pascal

    Example: HouseAddress

    Avoid to repeat table name in the column name, for example, For table 'Employee', use 'Name' for the column of employee name.

  • Primary Key Name

    Style: Pascal, PK_${TableName}

    Example: PK_Employee

  • Index Name

    Style: Pascal, UK_\({Column1Name}_\){Column2Name} for unique indexes.

    Use IK_\({Column1Name}_\){Column2Name} for non-unique indexes.

    Example: UK_Code

  • Foreign Key Name

    Style: Pascal, FK_\({Column1Name}_\){Column2Name}

    Example: FK_DepartmentId

Columns

Text columns

  • Do use unicode data type to define text columns.
  • Do use nvarchar for variable length text columns.

Date/Date Time

  • If the value of a date column is expected to present same text result among different time zone, use numeric or text data type to define date/date-time columns.

    If we define a column with date data type, default, most program language will use date-time type to store values from the column, we should realize the date value will be changed when the data is transited to a different time-zone. For example:

    2001/01/15, On the database server, timezone is +8.

    2001/01/15, On the application server, timezone is +8.

    2001/01/15 01:00:00, On the client, timezone is +9.

    So if it is a problem to you, try to use a integer or text data type to store the value.

Tips: consider the case carefully. ask these questions:

If your application will be used in different time-zone?

If you only use date part for the column?

If you only use time part for the column?

Nullable

  • Avoid to define a column as nullable.

    Avoid to use null would reduce programing bugs, and bring better performance.

  • Do Not use null for numeric columns if it has same meaning as zero.

  • Do Not use null for text columns if it has same meaning as empty.

  • May use null in a reference column provide that null is acceptable.

Keys

Primary Keys

  • Do create a primary key for any tables.
  • Recommend to use one column for the primary key.
  • Use '${TableName}Id' for the name of the primary key column, the column is denoted as 'Id' columns.
  • Recommend to use integer data type for the primary key column.
  • Avoid change the value of the primary key column after created.
  • It is acceptable to show the the value of the primary key column to customers if need.

Foreign Keys

  • Do create a foreign key if there is a relation between 2 tables.

    It is useful to keep data integrity.
  • Carefully use delete cascade clause when creating the foreign keys relationship.

Tips: Be careful, Use delete cascade is also dangerous. consider it twice before use it.

Database-specific constraints

  • Avoid to use reversed words for name of objects of databases

Tips: please read the reversed words from database you will use

  • Avoid to use system prefix in your object names
  • Check length limitation of object names of databases

Tables

Entity Tables

Like departments, employee etc, we store these kind of information into entity tables.

In most case, the table like:

  • Definition sample
Employee {EmployeeId, Code, Name, DepartmentId, ...}.

If in your system, an employee only exists in one department, you may use above definition.

Tree Tables

Like most organization, departments will be constructed as a tree, there are some top level departments (or is a root department), except these top level departments, departments must have one and only have one parent department.

We define this kind of table as:

  • Definition sample
Department{DepartmentId, Code, Name, **ParentId**, ...}.

In most case, for the usage convenience, we will define a tree table for each tree relationship, denoted as a tree table.

  • Definition sample

    DepartmentTree{ParentId, ChildId}.

    For a parent department, The table stores itself and all its descendants.

    From a view of a child department, the table stores itself and all its ancestors.

Hierarchical Tables

Different as tree tables, in the hierarchical tables, a child would have 0 to n parents.

For example, groups and users:

  • Rules

    • an user would exists in multiple groups.
    • an groups would exists in multiple groups.
  • Definition sample

User(userId, Name, isGroup)
GroupUser(parentId, userId)
GroupUserTree(parentId, userId)

The table GroupUser stores the direct relationships.

Instead, the table GroupUserTRee stores the redundant relationships like tree tables above.

Database Design Guidelines的更多相关文章

  1. [书籍]重温《Framework Design Guidelines》

    1. 前言 最近重温了<Framework Design Guidelines>. <Framework Design Guidelines>中文名称为<.NET设计规范 ...

  2. 数据库设计(二)Introduction to Database Design

    原文链接:http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html Introduction to Databa ...

  3. Test Design Guidelines for Reusability

    Last Updated: JAN.10.2008 From: http://safsdev.sourceforge.net/sqabasic2000/TestDesignGuidelines.htm ...

  4. Dynamic Library Design Guidelines

    https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100 ...

  5. SAP成都C4C小李探花:浅谈Fiori Design Guidelines

    Jerry: 我和周帅认识不久,自去年7月SAP成都研究院Cloud for Customer(以下简称为C4C)开发团队组建至今,根据这段时间和周帅愉快的合作经历,我觉得如果把周帅比作我读过的小说里 ...

  6. database design three form

    https://www.cnblogs.com/linjiqin/archive/2012/04/01/2428695.html

  7. Database Design for Sexbale Forum

    Mars March 17, 2015

  8. API Design

    REST API Design Guidelines V 1.0.201208 Draft 5 Last Updated: 08/31/2012 1       简介 本文档旨在规范REST API的 ...

  9. 【DB】database introduction

    database applications: – Banking System,– Stock Market,– Transportation,– Social Network,– Marine Da ...

随机推荐

  1. 求解数独难题, Sudoku问题(回溯)

    Introduction : 标准的数独游戏是在一个 9 X 9 的棋盘上填写 1 – 9 这 9 个数字,规则是这样的: 棋盘分成上图所示的 9 个区域(不同颜色做背景标出,每个区域是 3 X 3 ...

  2. Mybatis的mapper代理开发dao方法

    看完了之前的mybatis原始的dao开发方法是不是觉得有点笨重,甚至说没有发挥mybatis 作为一个框架的优势.总结了一下,原始的dao方法有以下几点不足之处 dao接口实现方法中存在大量的模板方 ...

  3. MyEclipse的多模块Maven web(ssm框架整合)

    Maven的多模块可以让项目结构更明确,提高功能的内聚,降低项目的耦合度,真正的体现出分层这一概念. 我们在操作中,要明白为什么这样做,要了解到更深的层次,这样,我们就不限于个别软件了. 话不多说,直 ...

  4. api-gateway实践(03)新服务网关 - 网关请求拦截检查

    参考链接:http://www.cnblogs.com/jivi/archive/2013/03/10/2952829.html 一.为什么要拦截检查请求? 防止重放攻击.篡改重放,进行使用规格检查 ...

  5. python入门(7)Python程序的风格

    python入门(7)Python程序的风格 Python采用缩进方式,写出来的代码就像下面的样子: # print absolute value of an integer: a = 100 if ...

  6. windbg分析Kernel32.dll导出表

    写在前面的话: 继续上篇,在获得了Kernel32.dll基址的基础上,分析它的导出表结构: 对PE结构不太熟悉的同学,可以参考看雪论坛里的一篇帖子:https://bbs.pediy.com/thr ...

  7. zoj 3950 how many nines

    https://vjudge.net/problem/ZOJ-3950 题意: 给出两个日期,计算从第一个日期开始到第二个日期,每一天的日期中的9加起来一共有多少个. 思路: 看题解补的题.首先看这题 ...

  8. Struts(十七):通过CURD来学习paramsPrepareParams拦截器栈

    背景: 通过上一章节<Struts(十六):通过CURD来学习Struts流程及ModelDriven的用法>学习了ModelDriven拦截器的用法,上章节中讲到了edit功能. 要修改 ...

  9. 南京邮电大学java程序设计作业在线编程第一次作业

    王利国的"Java语言程序设计第1次作业(2018)"详细 作业结果详细 总分:100 选择题得分:40  1. Java语言中,基本数据类型一共有( )种. A.16 B.2 C ...

  10. mysql新建表设置为utf8

    CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;