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 ...
随机推荐
- Code::Blocks出现64-Bit mode not compled in解决方法
原因是:Settings->compilter你选了Target x86 _64(64bit),选择Target x86 _32(32bit)即可 废了老半天劲才找到原因,希望能让朋友们少走弯路
- 新概念英语(1-97)A Small Blue Case
Lesson 97 A small blue case 一只蓝色的小箱子 Listen to the tape then answer this question. Does Mr. Hall get ...
- Linux将端口设置进防火墙的白名单
1.先检查linux服务器的端口是否被防火墙拦住 `telnet 172.168.1.101 8080后面跟端口号,如果连接上证明是防火墙白名单.如果没有配置 vi /etc/sysconfig/ip ...
- HTML mate标签
META标签分两大部分:HTTP标题信息(http-equiv)和页面描述信息(name). http-equiv http-equiv类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助正 ...
- kafka_2.12-1.1.0 生产与消费java实现示例
环境准备: 1)需要在maven工程中引入依赖: <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka --> &l ...
- ZOJ-1649 Rescue---BFS+优先队列
题目链接: https://vjudge.net/problem/ZOJ-1649 题目大意: 天使的朋友要去救天使,a是天使,r 是朋友,x是卫兵.每走一步需要时间1,打倒卫兵需要另外的时间1,问救 ...
- cookie的实现原理
cookie技术通过在请求和响应报文中写入cookie信息来控制客户点的状态 cookie会根据从服务器端发送的响应报文内的一个叫做set-cookie的首部字段信息,通知客户端保存cookie 当下 ...
- 参加Java培训到底靠不靠谱?
导读 科技越发展,社会越进步,人们越便利,便衍生出更多的人从事程序员这个高大上的职业,可哈尔滨Java培训学校这么多,到底靠不靠谱,会不会处处是陷阱,爱尚实训帮你擦亮眼 随着时代的发展,越来越多的人对 ...
- 列表(list)之一定义 添加 删除 排序 反转 索引等其他操作
1.定义: 创建一个列表,只要把逗号分隔的不同的数据项使用方括号括起来即可,序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. # 列表list1=[&q ...
- countUp.js-让数字动起来
先上一段示例代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...