11招教你如何玩转数据库设计跬

Oracle11g 使用create database手动创建数据库 1.使用create database创建数据库步骤: oradim -new -sid 数据库实例名 -intpwd 密码 oradim -new -sid OracleDB -intpw OraclePass 2.创建初始化数据参数文件(PFile),目标文件保存为initOracleDb.ora,保存地址为:D:\initOracleDb.ora db_name='OracleDb' 阅读详情

11 Important Database Designing Rules 

Posted by Shivprasad Articles | SQL April 04, 2012

 

Introduction

Rule 1:- What is the Nature of the application(OLTP or OLAP)?

Rule 2:- Break your data in to logical pieces, make life simpler

Rule 3:- Do not get overdosed with rule 2

Rule 4:- Treat duplicate non-uniform data as your biggest enemy

Rule 5:- Watch for data separated by separators.

Rule 6:- Watch for partial dependencies.

Rule 7:- Choose derived columns preciously

Rule 8:- Do not be hard on avoidingredundancy, if performance is the key

Rule 9:- Multidimensional data is a different beast altogether

Rule 10:- Centralize name value table design

Rule 11:- For unlimited hierarchical data self-reference PK and  FK

a1.jpg

Courtesy: - Image from Motion pictures

Introduction

Before you start reading this article let me confirm that I am not a guru in database designing. The below 11 points which are listed are points which I have learnt via projects, my own experiences and my own reading. I personally think it has helped me a lot when it comes to DB designing. Any criticism welcome.

The reason why I am writing a full blown article is, when developers sit for designing a database they tend to follow the three normal forms like a silver bullet. They tend to think normalization is the only way of designing. Due this mind set they sometimes hit road blocks as the project moves ahead.

In case you are new to normalization, then click and see3 normal forms in  action which explains all three normal forms step by step.

Said and done normalization rules are important guidelines but taking them as a mark on stone is calling for troubles. Below are my own 11 rules which I remember on the top head while doing DB design.

Rule 1:- What is the Nature of the application(OLTP or OLAP)?

When you start your database design the first thing to analyze is what is the natureof theapplication you are designing for, is it Transactional or Analytical.  You will find many developers by default applying normalization rules without thinking about the nature of the application and then later getting in to performance and customization issues. As said there are 2 kinds of applications transaction based and analytical based,let's understand what these types are.

Transactional: - In this kind of application your end user is more interested in CRUD i.e.  Creating, reading, updating and deleting records.  The official name for such kind of database is called as OLTP.

Analytical: -In these kinds of applications your end user is more interested in Analysis, reporting, forecasting etc. These kinds of databases have less number of inserts and updates. The main intention here is to fetch and analyze data as fast as possible. The official name for such kind of databases is OLAP.

a2.jpg

So in other words if you think insert, updates and deletes are more prominent then go for normalized table design or else create a flat denormalized database structure.

Below is a simple diagram which shows how the names and address in the left hand side is a simple normalized table and by applying denormalized structure how we have created a flat table structure.

a3.jpg

Rule 2:- Break your data in to logical pieces, make life simpler

This rule is actually the 1st rule from 1st normal formal.  One of the signs of violation of this rule is if your queries are using too many string parsing functions like substring, charindexetc , probably this rule needs to be applied.

For instance you can see the below table which has student names , if you ever want to query student name who is having "Koirala" and not "Harisingh" , you can imagine what kind of query you can end up with.

So the better approach would be to break this field in to further logical pieces so that we can write clean and optimal queries.

a4.jpg

Rule 3:- Do not get overdosed with rule 2

Developers are cute creatures. If you tell them this is the way, they keep doing it; well they overdo it leading to unwanted consequences. This also applies to rule 2 which we just talked above.  When you think about decomposing, give a pause and ask yourself is it needed. As said the decomposition should be logical.

For instance you can see the phone number field; it's rare that you will operate on ISD codes of phone number separately(Until your application demands it).  So it would be wise decision to just leave it as it can lead to more complications.

a5.jpg

Rule 4:- Treat duplicate non-uniform data as your biggest enemy

Focus and refactor duplicate data. My personal worry about duplicate data is not that it takes hard disk space, but the confusion it creates.

For instance in the below diagram you can see "5th Standard" and "Fifth standard" means the same. Now you can say due to bad data entry or poor validation the data has come in to your system. Now if you ever want toderive a report they would show them as different entities which is very confusing from end user point of view.

a6.jpg

One of the solutions would be to move the data in to a different master table altogether and refer then via foreign keys. You can see in the below figure how we have created a new master table called as "Standards" and linked the same using a simple foreign key.

a7.jpg

Rule 5:- Watch for data separated by separators.

The second rule of 1st normal form says avoid repeating groups. One of the examples of repeating groups is explained in the below diagram. If you see the syllabus field closely, in one field we have too much data stuffed.These kinds of fields are termed as "Repeating groups". If we have to manipulate this data, the query would be complex and also I doubt performance of the queries.

a8.jpg

These kinds of columns which have data stuffed with separator's need special attention and a better approach would be to move that field to a different table and link the same with keys for better management.

aa9.jpg

So now let's apply the second rule of 1st normal form "Avoid repeating groups". You can see in the above figure I have created a separate syllabus table and then made a many-to-many relationship with the subject table.

With this approach the syllabus field in the main table is no more repeating and having data separators.

Rule 6:- Watch for partial dependencies.

aa10.jpg

Watch for fields which are depending partially on primary keys. For instance in the above table we can see primary key is created on roll number and standard. Now watch the syllabus field closely. Syllabus field is associated with a standard and not with a student directly (roll number).

Syllabus is associated with the standard in which the student is studying and not directly with the student. So if tomorrow we want to update syllabus we have to update for each student which is pain staking and not logical. It makes more sense to move these fields out and associate them with the standard table.

You can see how we have move the syllabus field and attached the same to standards table.

This rule is nothing but second normal form "All keys should depend on the full primary key and not partially".

Rule 7:- Choose derived columns preciously

a11.jpg

If you are working on OLTP applications must be getting rid of derive columns would be good thought, until there is some pressing reason of performance. In case of OLAP where we do lot of summations, calculations these kinds of fields are necessary to gain performance.

In the above figure you can see how average field is dependent on marks and subject. This is also one of form of redundancy. So for such kind of fields which are derived from other fields give a thought are they really necessary.

This rule is also termed as 3rd normal form "No columns should depend on other non-primary key columns". My personal thought is do not apply this rule blindly see the situation; it's not that redundant data is always bad. If the redundant data is calculative data , see the situation and then decide do you want to implement the third normal form.

Rule 8:- Do not be hard on avoidingredundancy, if performance is the key

a12.jpg

Do not make it a strict rule that you will always avoid redundancy. If there is a pressing need of performance think about de-normalization. In normalization you need to make joins with many table and in denormalization the joins reduces and thus increasing performance.

Rule 9:- Multidimensional data is a different beast altogether

OLAP projects mostly deal with multidimensional data. For instance you can see the below figure, you would like to get sales as per country, customer and date. In simple words you are looking at sales figure which have 3 intersections of dimension data.

a13.jpg

For such kind of situations a dimension and fact design is a better approach. In simple words you can create a simple central sales fact table which has the sales amount field and he makes a connection with all dimension tables using a foreign key relationship.

a14.jpg

a15.jpg

Rule 10:- Centralize name value table design

Many times I have come across name value tables. Name and value tables means it has key and some data associated with the key. For instance in the below figure you can see we have currency table and country table. If you watch the data closely they actually only have Key and value.

a16.jpg

For such kind of table creating one central table and differentiating the data by using a type field makes more sense.

Rule 11:- For unlimited hierarchical data self-reference PK and FK

Many times we come across data with unlimited parent child hierarchy.  For instance consider a Multi-level marketing scenario where one sales person can have multiple sales people below them. For such kind of scenarios using a self-referencing primary key and foreign key will help to achieve the same.

a17.jpg

This article is not meant to say that do not follow  normal forms , but do not follow them blindly , look at your project nature and type of data you are dealing with.

a18.jpg

Out of full respect, below is a video which explains 3 normal forms step by step using a simple school table.

 

Rule 1:弄清(OLTP或OLAP)应用的本质是什么?

当开始制作数据表单设计时,首先,要分析你设计的这个程序的本质是什么?是事务性还是分析性的?你会发现许多开发者会默认应用常规化规则,随后才考虑性能问题而不考虑应用的本质。

关于事务性和分析性,一起来看下两者区别。

Transactional:这种应用,用户对CRUD较为感兴趣,即创建、读取、更新和删除记录。这种数据,官方名称之位OLTP。

Analytical:用户对分析、报告、预测等方面感兴趣。这类数据库很少有嵌入和更新。主要目的是为了尽快获取和分析数据。官方名称之为OLAP。

换句话说,如果你想以嵌入、更新、删除为重点,可选择常规化的表单设计或者创建一个简单的非常规化的数据架构。

下面是一个简单的图表,左侧显示名称和地址,采用非规范化结构设计出的一款简单的常规表单。

Rule 2:将数据按照逻辑思维分成不同的块,让生活更简单

这个规则其实就是 “三范式” 中的第一范式。这样设计的目标,是为了当你需要查询套多的字符串解析功能时,如子串,charindexetc,它能为你提供这项功能。

例如,注意观看下面的图表,如果你想查询某个学生的姓名,通过“Koirala”和“Harisingh”来进行区分。

因此,更好的方法就是打破数据逻辑思维,以便我们编写更加简洁、容易查询的表单。

Rule 3:当数据太多时,rule 2不可用

开发者们的思维有时很单一,如果你告诉他们某种方式,他们会一直这么做下去,要知道过度的使用会造成不必要的麻烦。正如我们之前谈到的rule 2,首先要进行分解,明确自己的需求。例如,当你看到电话号码字段时,你可以在ISD代码上进行操作区分这些电话号码(直到满足你的需求)。尽管这是不错的方法,但会给你带来更多的并发症。

Rule 4:将重复、不统一的数据视作你最大的敌人

聚焦和重构复制数据。我比较担心的不是复制数据所需要的磁盘空间而是它因此而造成的混乱。

从下面的图表中,“5th Standard”和“Fifth standard”意思是相同的,你可以说是因为数据或者验证数据录入到你的系统原因,如果你想通过报表来显示他们的不同之处,从用户的角度开看,这是非常困难的。

其中一个解决方法就是将不同的任务栏把相同的数据通过新建一个键入值联接在一起。如图。我们通过创建一个新的条目“Standards”即可将数据重新排,显示相同的部分。

Rule 5:注意被分隔符分割的数据

前面的规则2即“第一范式”提到避免数组重复,如图所示。如果你看到教学大纲紧密排列在一起,这个领域中需要很多数据来填充,这种我们称之为“重复数组”。如果我们必须操纵这些数据,单凭查询是很困难的,我甚至还怀疑是否具备这个查询功能。

这些带分隔符的数据需要特别注意,如何利用更好的方法将这些数据移动到一个不同的任务栏中,以便更好的分类呢?如图:

如图所示,可以看到我创建了一个独立的教学科目条目,然后列出了与之有相关联的科目。这种方法主要适用于在教学大纲领域,避免过多的重复和数据分隔符中。

Rule 6:当心数据依赖

观察该领域中的部分列表。如图,我们创建了roll number和standard,可以看到教学科目紧密联系在一起,但与学生学习的科目没有直接关联。如果我们想给每位学生更新教学科目,这似乎看起来是不符合逻辑的,但是通过键入standard条目转换这些数据就可达到目的。

这个规则告诉我们“所有的键入都应该依赖主键”。All keys should depend on the full primary key and not partially。

Rule 7:选择派生列

如果你想进行OLTP应用首先得筛选出派生列,在OLAP中我们需要做一些求和,方可获得uixie很好的性能。如图,求的平均数需要利用marks和subject两列。

这个规则被称为第三范式,“不应该有依赖于非主键的列”(No columns should depend on other non-primary key columns)我个人认为是不能盲目使用此规则。如果该数据是计算过的数据,看清状况然后在决定实施第三范式。

Rule 8:如果性能很关键,不要避开冗余数据

如果你迫切的考虑到性能规范化问题,通常情况下需要连接许多列表以及减少增加非规范化的列表以便来提高数据图表性能。

Rule 9:数据多、繁杂

OLAP项目主要是为了处理数据繁多,例如,如图所示,假如你想获得每个国家、每个用户、每年的销售额度。对于这种情况,你可以创建一个实际销售列表条目(sales fact table)。

Rule 10:设计name value table列表

明值表意味着它有一些键,这些键被其他数据关联着。如图所示,我们需要弄清楚currency table (货币列)和country table(国家列),图中键入值(数字部分)显示的就是我们所需要的数据。

通过创建键入值(Type)来显示出不同区域的数据。

Rule 11:无限制结构数据,自定义PK和FK

我们会经常碰到一些无限父子分级结构的数据。例如:考虑到一个多层次的营销方案,其中一个销售人员可以领导多个销售人员。在这种情况下,你可以使用自定义的主键和设置外键来帮助你实现统一。

您可以根据自身的项目需求选择不同的数据处理方法。如下所示:三种常规范式。

数据仓库设计思路 数据仓库一些设计思路和总结 1、数据仓库模型设计分为概念模型、逻辑模型和物理模型;数据仓库建模方法:实体关系模型、维度建模。数据仓库逻辑模型设计:确定主题域->粒度层次划分->确定数据分割策略->关系模式确定。数据仓库物理模型设计:确定数据存储结构->确定数据仓库索引策略->对表归并优化存储分配。 2、维度建模-维表设计原则:维表用文本属性取代编码,维表属性对应的是分析的角度。维度可以分为层次 阅读详情

相关推荐

A5M2数据库管理工具,数据库设计,ER图

A5M2数据库管理工具,MySQL数据库管理工具,A5,A5M2,数据库设计,ER图

[图解] 11招教你如何玩转数据库设计

在日常工作中,当我们遇到海量数据时,如何从中挑选出自己想要的数据呢?是盲目的查找,还是寻求新的解决方案亦或是通过技巧来获取?开发者在设计一个数据表单时,往往会遵循三条常用形式,他们认为常规模式是设计的唯一途径。然而由于开发者一开始就抱有这种心态,使数据表单设计变得墨守成规,阻碍了它的创新。 作者Shivprasad 从平时的工作项目中积累了一些经验,向我们介绍了11款制作数据表单技巧,当设计到数...

weixin_33906657的博客 772

GAMES101:MacOS作业环境搭建

查看gcc/clang的位置产看gcc/clang的版本1.1.2 安装cmake。

weixin_38844255的博客 716

数据库设计

数据库设计一.数据库设计概述1.数据库设计的特点2.数据库设计方法3.数据库设计的基本步骤4.数据库设计过程中的各级模式二.需求分析1.需求分析的任务2.需求分析的方法3.数据字典三.概念结构设计1.概念模型2.E-R模型3.概念结构设计 一.数据库设计概述 ①数据库设计是指对于一个给定的应用环境,构造(设计)优化的数据库逻辑模式和物理结构,并据此建立数据库及其应用系统,使之能够有效地存储和管理数据,满足各种用户的应用需求,包括信息管理要求和数据操作要求。 ②信息管理要求:在数据库中应该存储和管理哪些数据

luran的博客 2万+

ads传统功放设计笔记(3)

传统功放设计的流程一般包括以下这些步骤: 1、明确设计目标 2、选择功放管子 3、确定静态工作点 4、设计偏置电路 5、判断稳定性 6、负载与源牵引 7、输入输出阻抗匹配 8、原理图优化 9、大信号仿真 10、版图设计 11、版图联合仿真 12、pcb设计 第二节我们设计仿真了功放的原理图。之后我们需要对版图进行设计和仿真。 10、版图设计 首先将S参数控件都打叉,还要去掉电源、源负载阻抗、地、芯片、电容。在原先电容和芯片的位置加上gap,设置好长度和间隔。之后在电源引脚、输入输出引脚和隔离的两端加上端口。

qq_40995480的博客 6027

Multisim新手必看:从零搭建数字时钟仿真电路(附完整原理图)

本文详细介绍了如何使用Multisim从零开始搭建数字时钟仿真电路,涵盖晶振电路设计、计数电路实现、校时功能配置等关键步骤。通过完整的原理图和实用技巧,帮助新手快速掌握Multisim仿真设计,实现精准的数字时钟功能。

ios99的博客 328

一篇文章带你玩转SQL server数据库,喜欢三联

一种关系型数据库系统 美国Microsoft公司推出的一种关系型数据库系统。SQL Server是一个可扩展的、高性能的、为分布式客户机/服务器计算所设计的数据库管理系统,实现了与WindowsNT的有机结合,提供了基于事务的企业级信息管理系统方案。

烛照@123的博客 1543

晟矽微MC32F7361定时器的使用案例说明

110所以TIMER0所用的频率是FCPU的1/64,也就是8/64MHZ. 为1/8MHZ。//io口下拉电阻 1:enable 0:disablea。//io口上拉电阻 1:enable 0:disable。//io口下拉电阻 1:enable 0:disable。//io口上拉电阻 1:enable 0:disable。//io口下拉电阻 1:enable 0:disable。//io口上拉电阻 1:enable 0:disable。

liyanfei123456的博客 1130

11招教你如何玩转数据库设计

在日常工作中,当我们遇到海量数据时,如何从中挑选出自己想要的数据呢?是盲目的查找,还是寻求新的解决方案亦或是通过技巧来获取?开发者在设计一个数据表单时,往往会遵循三条常用形式,他们认为常规模式是设计的唯一途径。然而由于开发者一开始就抱有这种心态,使数据表单设计变得墨守成规,阻碍了它的创新。 作者Shivprasad 从平时的工作项目中积累了一些经验,向我们介绍了11款制作数据表单技巧,当设计

Golden_lion的博客 1387

Delta机器人:运动学正反解分析

Delta机器人:运动学正反解分析 一、Delta机构简介 Delta机构是并联机构中的一种典型机构,起原始结构如图1所示。Delta机构由R.Clavel 博士在 1985年发明,是现在并联机器人中使用最多的一种,具备了并联机构所特有的优点,负载能力强、效率高、末端执行器精度高、运动惯性小,可以高速稳定运动等。因此在机器人领域获得了越来越广泛的应用。以实现高速、精准、高效的运动。           &n

花洛兮灬 3万+

微信小程序转发功能异常报错 由于小程序违规分享功能暂时无法使用的解决办法

小程序右上角转发功能被封,不代表你违规了,而可能是你没认证、没备案!很多功能都是“先合规、后开发”,踩坑就晚了,别像我一样绕了三圈才发现问题。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 2610

11招教你如何玩转数据库设计(转载)

11招教你如何玩转数据库设计 简介 在您开始阅读这篇文章之前,我得明确地告诉您,我并不是一个数据库设计领域的大师。以下列出的 11 点是我对自己在平时项目实践和阅读中学习到的经验总结出来的个人见解。我个人认为它们对我的数据库设计提供了很大的帮助。实属一家之言,欢迎拍砖 : ) 我之所以写下这篇这么完整的文章是因为,很多开发者一参与到数据库设计,就会很自然地把 “三范式” 当作银弹一样来使用。...

weixin_30591551的博客 957

osgEarth加载大疆数据

【代码】osgEarth加载大疆数据。

weixin_44769745的博客 308

【数据库设计】11招教你如何玩转数据库

在日常工作中,当我们遇到海量数据时,如何从中挑选出自己想要的数据呢?是盲目的查找,还是寻求新的解决方案亦或是通过技巧来获取?开发者在设计一个数据表单时,往往会遵循三条常用形式,他们认为常规模式是设计的唯一途径。然而由于开发者一开始就抱有这种心态,使数据表单设计变得墨守成规,阻碍了它的创新。 Rule 1:弄清(OLTP或OLAP)应用的本质是什么? 当开始制作数据表单设计时,首先,要分

AG的博客 972

OmniDrive(3):逐行代码详解

模型效果: 端到端联合规划与推理 接下来,简单介绍下训练的配置 1.1 模型配置 模型基于sparse query based的3D Bev感知框架StreamPetr ,用query来编码动态目标(如车辆、行人)和静态地图元素(如车道线)。(1) tran、test和val数据配置 指定真值的文件路径: ann_file 指定输出处理的pipeline: 训练使用, test 和val使用 指定是否需要时序训练seq_mode (2)数据处理pipeline 自定义的Dataset 通过类实现,训

@bangbang的博客 719

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

一文读懂数据库、数据仓库、数据平台、数据中台、数据湖

数据库是用于存储、管理、维护和检索数据的系统。是所有软件应用、网站、企业信息系统和数据驱动决策的基础。简单来说就是:数据库就是一个存储信息(水)的容器。数据库使用场景-图1数据库主要分为两种类型:关系型数据库和非关系型(NoSQL)数据库。非关系型又分为四种类型:键值型、列存储型、文件型和图形数据库(这块后面有时间详细说下)。数据库类型-图2题外话:某些数据库(如 MongoDB)可以分为多个类别,因为它们支持不同的数据模型。此外,所提供的列表并不详尽,因为每个类别中还有许多其他数据库可用。

m0_59235945的博客 6415

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

STM32寄存器白话指南:从时钟使能到中断触发的硬件因果链

寄存器不是内存地址,而是硬件状态机的控制接口——这一基础概念是理解嵌入式底层开发的关键。其操作原理涉及时钟门控同步、写1清零机制、原子性访问约束及多模块依赖关系,技术价值在于规避竞态、死锁与静默失效等90%的诡异Bug。典型应用场景包括GPIO初始化、外部中断配置、Flash等待周期调优及低功耗唤醒路径构建。本文以STM32F4系列为载体,聚焦RCC时钟使能、EXTI中断映射、SYSCFG重映射等高频实操环节,揭示寄存器字段背后真实的硬件因果链,帮助开发者从‘查手册’跃迁至‘读硬件’。

weixin_33755557的博客 314

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

oracle database firewall 配置 保护 db,Oracle DB control配置启动

今天打算启用一下Oracle Database 11g的Database Control,发现初始并未安装:[Oracle@test126 ~]$ emctl startEM Configuration issue. /opt/Oracle/product/11.1.0/test126.hurray.com.cn_dodd not found.遇到这类问题,可以通过重新配置,来创建EM的配置文件:...

weixin_39602569的博客 456
上一篇: UML中的几种关系(依赖,关联,泛化,实现)
下一篇: 软件设计师成绩
backzero
博客等级 码龄15年 3粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值