View on GitHub

Software Development Guidelines

软件项目管理规范

Database Design Guidelines

Principles

Name Style

Columns

Text columns

Date/Date Time

Nullable

Keys

Primary Keys

Foreign Keys

Database-specific constraints

Tables

Entity Tables

Like departments, employee etc, we store these kind of information into entity tables.
In most case, the table like:

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:

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.

Hierarchical Tables

Different as tree tables, in the hierarchical tables, a child would have 0 to n parents.
For example, groups and users:

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.