首先,对关系型数据库的表进行四种分类定义:

Basis 根基,Content 内容, Description 说明, Extension 扩展。

Basis:Baisis 表是唯一的,为了实现标准而得到方便,名称可以就定义为 Basis。这个表是分布式数据库的基础,以极少量的必要信息记录所有表以及表名,在设计的角度所有对表的访问都从这张表开始。

Content:Content 表就是数据库的实际内容,根据需求进行设计。应该为每一类的表提供一个前缀的分类命名,并且将定义记录在 Description 里。

Description:Description 表是用来对表的结构设计进行说明的,可以通过查询的方式获取对整个表的描述,方便引导其他设计人员以及未来的自己迅速的了解表的设计结构。它也是唯一的,为了实现标准而得到方便,名称可以就定义为 Description。

Extension:鉴于关系型数据库数据结构的简单性,Extension 表可以作为对主要内容表提供辅助的扩展,命名应该定义为 表名_Extension,它的结构和定义应该记录在 Description 表里。 通常以键值对作为列。

SQLite 代码示例 共 2 种:

第 1 种:编号索引示例

--《编号索引示例》

-- #1 创建主表和说明表
--
-- 步骤 1/2 创建表

--create table Basis
--(id integer primary key autoincrement,
--category text not null default'暂未分类',
--name text not null unique,
--version integer not null unique,
--tableName text not null unique);
--
--create table Basis_Extension
--(keyName text not null,
--keyValue text not null,
--unique(keyName,keyValue));
--
--create table Description
--(tableType text not null unique,
--description text not null);
--
--create table Description_Extension
--(keyName text not null,
--keyValue text not null,
--unique(keyName,keyValue));

-- 步骤 2/2 插入值

--insert into Description values('Description','<tableType>(唯一):记录所有类型的表,多表通过TableName_[1]或TableName_[a]来分别表示通过数字或字符区分的表。 <description>:对该表的各列进行描述');
--insert into Description values('Description_Extension','通过键值对记录进行任意的补充说明');
--insert into Description values('Basis','记录所有项目的编号(唯一、自增长)、分类、名称(唯一)、版本(唯一)、表名(唯一)');
--insert into Description values('Basis_Extension','通过键值对记录。<recoveryId>:回收的ID');

----
-- #2 创建内容表 

-- 实际编程中,这里必须使用编码的方式获取下一个ID,并手写内容表的名称。
--
-- 步骤 1/2 创建表
--
--insert into Basis values (1, '小乘', '无量寿经',1, 'FoJing_1' );
----
--create table FoJing_1
--(chapterNumber integer not null default'1' unique,
--chapterName text,
--content text not null);
--
--create table FoJing_1_Extension
--(KeyName text not null,
--KeyValue text not null,
--unique(keyName,keyValue));

--insert into Description values('FoJing_[1]','记录佛经的章节数(唯一)、章节名(可空)、名称、内容');
--insert into Description values('FoJing_[1]_Extension','通过键值对记录佛经的版本、更新时间、编辑者');

-- 步骤 2/2 插入值

--insert into FoJing_1 values (1,null,'经文内容');
--insert into FoJing_1_Extension values('updateTime','codeForCurrentTime'),('editor','一星');

-- #3 更新内容表

--update FoJing_1 set content = '新的经文内容' where chapterNumber = '1';
--update Basis set version = version + 1 where id = 1;
--update FoJing_1_Extension set keyValue = 'codeForCurrentTime' where keyName = 'updateTime';

-- #4 删除内容表

--delete from Basis where id = '1';
--insert into Basis_Extension values ('recoveryId','1');
--drop table if exists FoJing_1;
--drop table if exists Fojing_1_Extension;

第 2 种:数字索引示例

--《数字索引示例》
--
-- #1 创建主表和说明表
--
-- 步骤 1/2 创建表

--create table Basis
--(id integer primary key autoincrement,
--category text not null default'暂未分类',
--indexStart integer not null unique,
--tableName text not null unique);
--
--create table Basis_Extension
--(keyName text not null,
--keyValue text not null,
--unique(keyName,keyValue));
--
--create table Description
--(tableType text not null unique,
--description text not null);
--
--create table Description_Extension
--(keyName text not null,
--KeyValue text not null,
--unique(keyName,keyValue));

-- 步骤 2/2 插入值

--insert into Basis_Extension values ('indexLength','10000');
--insert into Description values('Description','<tableType>(唯一):记录所有类型的表,多表通过TableName_[1]或TableName_[a]来分别表示通过数字或字符区分的表。 <description>:对该表的各列进行描述');
--insert into Description values('Description_Extension','通过键值对记录进行任意的补充说明');
--insert into Description values('Basis','记录所有项目的编号(唯一、自增长)、分类、索引起始数(唯一)、表名(唯一)');
--insert into Description values('Basis_Extension','通过键值对记录。<startLength>:索引步长');

-- #2 创建内容表
--
-- 步骤 1/4 创建表
--
--insert into Basis values (1, 'store','1', 'Account_1' ),(2, 'store','10001','Account_2');
--
--create table Account_1
--(accountNumber integer primary key,
--accountName text not null,
--accountPassword text not null,
--email text,
--otherInfo text);
--
--create table Account_1_Extension
--(KeyName text not null,
--KeyValue text not null,
--unique(keyName,keyValue));
--
--create table Account_2
--(accountNumber integer not null unique,
--accountName text not null,
--accountPassword text not null,
--email text,
--otherInfo text);
--
--create table Account_2_Extension
--(KeyName text not null,
--KeyValue text not null,
--unique(keyName,keyValue));
--
--insert into Account_1_Extension values ('accountCount','0');
--insert into Account_2_Extension values ('accountCount','0');
--
--insert into Description values('Account_[1]','记录数字帐号(唯一)、帐号名、帐号密码等等信息');
--insert into Description values('Account_[1]_Extension','通过键值对记录该区域账户的实际数量,以及其他辅助信息');

-- 说明:

-- 步骤 2/4 查询表信息
--
--select keyValue from Basis_Extension where keyName = 'indexLength';
--
--select tableName from Basis where indexStart < 18546 and indexStart > (18546 - 10000);

-- 步骤 3/4 插入值

--insert into Account_2 values (18546,'一星','md5-pw',null,null);

-- 步骤 4/4 更新扩展表

--update Account_2_Extension set keyValue = keyValue + 1 where keyName = 'accountCount';

-- #3 更新内容表

--update Account_2 set email = 'new@email.com' where accountNumber = '18546';

-- #4 删除内容表的值

--delete from Account_2 where accountNumber = '18546';
--update Account_2_Extension set keyValue = keyValue - 1 where keyName = 'accountCount';

#

分布式数据库的四分结构设计 BCDE的更多相关文章

  1. SDP(6):分布式数据库运算环境- Cassandra-Engine

    现代信息系统应该是避不开大数据处理的.作为一个通用的系统集成工具也必须具备大数据存储和读取能力.cassandra是一种分布式的数据库,具备了分布式数据库高可用性(high-availability) ...

  2. 开源分布式数据库中间件MyCat源码分析系列

    MyCat是当下很火的开源分布式数据库中间件,特意花费了一些精力研究其实现方式与内部机制,在此针对某些较为重要的源码进行粗浅的分析,希望与感兴趣的朋友交流探讨. 本源码分析系列主要针对代码实现,配置. ...

  3. erlang 分布式数据库Mnesia 实现及应用

    先推荐一篇:mnesia源码分析(yufeng)   - linear hash   ETS/DETS/mnesia 都使用了linear hash算法 http://en.wikipedia.org ...

  4. 分布式数据库中的Paxos 算法

    分布式数据库中的Paxos 算法 http://baike.baidu.com/link?url=ChmfvtXRZQl7X1VmRU6ypsmZ4b4MbQX1pelw_VenRLnFpq7rMvY ...

  5. Distributed4:SQL Server 分布式数据库性能测试

    我使用三台SQL Server 2012 搭建分布式数据库,将一年的1.4亿条数据大致均匀存储在这三台Server中,每台Server 存储4个月的数据,Physical Server的配置基本相同, ...

  6. Distributed3:SQL Server 创建分布式数据库

    分布式数据库的优势是将IO分散在不同的Physical Disk上,每次查询都由多台Server的CPU,I/O共同负载,通过各节点并行处理数据来提高性能,劣势是消耗大量的网络带宽资源,管理难度大.在 ...

  7. 【Java EE 学习 30】【闪回】【导入导出】【管理用户安全】【分布式数据库】【数据字典】【方案】

    一.闪回 1.可能的误操作 (1)错误的删除了记录 (2)错误的删除了表 (3)查询历史记录 (4)撤销已经提交了的事务. 2.对应着以上四种类型的误操作,有四种闪回类型 (1)闪回表:将表回退到过去 ...

  8. 云时代的分布式数据库:阿里分布式数据库服务DRDS

    发表于2015-07-15 21:47| 10943次阅读| 来源<程序员>杂志| 27 条评论| 作者王晶昱 <程序员>杂志数据库DRDS分布式沈询 摘要:伴随着系统性能.成 ...

  9. SQL Server分布式数据库技术(LinkedServer,CT,SSB)

    SQL Server自定义业务功能的数据同步 在不同业务需求的驱动下,数据库的模块化拆分将会面临一些比较特殊的业务逻辑处理需求.例如,在数据库层面的数据同步需求.同步过程中,可能会有一些比较复杂的业务 ...

随机推荐

  1. height:100%与height:inherit的区别

    一.兼容性 首先,inherit这个属性只是在ie8+才支持:100%支持ie6: 二.大多数情况下没有区别 在正常情况下height:100%与height:inherit没有任何区别: 1.父元素 ...

  2. 基于Unity3D 的Vuforia SDK开发基础教程

    最新博客地址已转到: http://blog.csdn.net/zzlyw?viewmode=contents   ------------------------------------------ ...

  3. 浅谈CPU和GPU的区别

    导读: CPU和GPU之所以大不相同,是由于其设计目标的不同,它们分别针对了两种不同的应用场景.CPU需要很强的通用性来处理各种不同的数据类型,而GPU面对的则是类型高度统一的.相互无依赖的大规模数据 ...

  4. django 强制登录最佳实践

    参考: https://python-programming.courses/recipes/django-require-authentication-pages/ 即通过中间件来做AOP拦截.不用 ...

  5. Python语言常见异常错误类型

    在运行或编写一个程序时常会遇到错误异常,这时python会给你一个错误提示类名,告诉出现了什么样的问题(Python是面向对象语言,所以程序抛出的异常也是类).能很好的理解这些错误提示类名所代表的意思 ...

  6. ffmpeg-20161003[04,05.06]-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 5 屏幕横向放大 20 像素 6 屏幕横向缩小 20 像素 S 下一帧 [ -2秒 ] +2 ...

  7. marquee实现文字移动效果;js+div实现文字无缝移动效果

    1.marquee实现文字移动: <marquee width="220px;" scrollamount="5" onmouseover="t ...

  8. Windows中遇到的些问题及解决办法

    1.win7 无法将程序锁定到任务栏 由于不正确的使用去掉桌面快捷键小箭头等,导致无法将程序固定到任务栏 如:http://jingyan.baidu.com/article/ac6a9a5e41bd ...

  9. 安装Python环境时遇到的问题

    问题描述:An error occurred during the installation of assembly 'Microsoft.VC90.MFC,version="9.0.210 ...

  10. Myeclipse下的struts2.3.8 配置 保证绝对好用

    转自:http://blog.csdn.net/oxuannishi/article/details/8538386 1.建立web project工程,我的结构如下: 2.这一步非常重要:引入必要的 ...