Database Design Guidelines
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_EmployeeIndex Name
Style: Pascal, UK_\({Column1Name}_\){Column2Name} for unique indexes.
Use IK_\({Column1Name}_\){Column2Name} for non-unique indexes.
Example: UK_CodeForeign 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的更多相关文章
- [书籍]重温《Framework Design Guidelines》
1. 前言 最近重温了<Framework Design Guidelines>. <Framework Design Guidelines>中文名称为<.NET设计规范 ...
- 数据库设计(二)Introduction to Database Design
原文链接:http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html Introduction to Databa ...
- Test Design Guidelines for Reusability
Last Updated: JAN.10.2008 From: http://safsdev.sourceforge.net/sqabasic2000/TestDesignGuidelines.htm ...
- Dynamic Library Design Guidelines
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100 ...
- SAP成都C4C小李探花:浅谈Fiori Design Guidelines
Jerry: 我和周帅认识不久,自去年7月SAP成都研究院Cloud for Customer(以下简称为C4C)开发团队组建至今,根据这段时间和周帅愉快的合作经历,我觉得如果把周帅比作我读过的小说里 ...
- database design three form
https://www.cnblogs.com/linjiqin/archive/2012/04/01/2428695.html
- Database Design for Sexbale Forum
Mars March 17, 2015
- API Design
REST API Design Guidelines V 1.0.201208 Draft 5 Last Updated: 08/31/2012 1 简介 本文档旨在规范REST API的 ...
- 【DB】database introduction
database applications: – Banking System,– Stock Market,– Transportation,– Social Network,– Marine Da ...
随机推荐
- kubernetes 手绘画,先收藏一下
- A、B同时打开一个页面进行同一条数据库记录进行修改,A修改完成后提交表单,A修改的数据保存完成后;当B也修改完成后,提交数据进行数据修改。此时B修改的内容会覆盖A修改的内容,请问如何避免?
A.B同时打开一个页面进行数据中的一条数据进行修改,A修改完成后提交表单,数据修改保存完成后B开始页面也修改完成,开始提交进行修改.此时B修改的内容会覆盖A的内容,请问如何避免? 通过搜索和我个人总结 ...
- C#:多进程开发,控制进程数量
正在c#程序优化时,如果多线程效果不佳的情况下,也会使用多进程的方案,如下: System.Threading.Tasks.Task task=System.Threading.Tasks.Task. ...
- spring boot 系列之四:spring boot 整合JPA
上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...
- OptionMenu选项菜单
#选项菜单 from tkinter import * root = Tk() variable=StringVar() variable.set('one') w = OptionMenu(root ...
- Spring源码分析:Spring IOC容器初始化
概述: Spring 对于Java 开发来说,以及算得上非常基础并且核心的框架了,在有一定开发经验后,阅读源码能更好的提高我们的编码能力并且让我们对其更加理解.俗话说知己知彼,百战不殆.当你对Spri ...
- lsdyna进阶教程-弹性球撞击刚性平板
在lsdyna基础教程中,我们做了一个关于刚性球撞击弹性平板的粒子,现在我们考虑另外一个问题,如果用弹性球撞击刚性地面该怎么做呢?是不是要从头开始建模,操作步骤是不是一样呢?其实很简单,将球和地面的材 ...
- [LeetCode] Number of Longest Increasing Subsequence 最长递增序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- [LeetCode] Delete Operation for Two Strings 两个字符串的删除操作
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- 【django之modelform】
一.什么是modelform ModelForm顾名思义就Form和Django的Model数据库模型结合体,可以简单.方便得对数据库进行增加.编辑操作和验证标签的生成: 举例说明: 比如我们的数据库 ...