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

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. 元素堆叠问题、z-index、position

    多次在项目中遇到html页面元素的非期待重叠错误,多数还是position定位情况下z-index的问题.其实每次解决类似问题思路大致都是一样的,说到底还是对z-index的理解比较模糊,可以解决问题 ...

  2. VS2015编译boost1.62

    VS2015编译boost1.62 Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有 ...

  3. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

  4. 高性能MySQL(五):查询性能优化

    当向MySQL 发送一个请求的时候MySQL 到底做了什么? 1.客户端发送一条查询给服务器 2.服务器先检查查询缓存,如果命中了缓存,则立即返回存储在缓存中的结果.否则进入下一阶段 3.服务器端进行 ...

  5. cocos2d-js 学习笔记 --安装调试(2)

    对于初学者安装cocos2d-js的环境并没有教程中说的那么简单,至少笔者是这么认为的 第一步,下载cocos2d-js的SDK,(先别着急运行) 第二步,安装Cocos2d console ,(Ma ...

  6. cxf ServerFactoryBean 生成基于soap1.2的WebServices

    //获得服务工厂bean ServerFactoryBean bean = new ServerFactoryBean(); HTTPTransportFactory httpTransportFac ...

  7. ReWriteDateControll

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. eclipse开发servlet,HttpServletRequest报红叉解决方案

    eclipse开发servlet,HttpServletRequest报红叉解决方案 今天突然间有兴致,想打一会代码,于是开发一个Servlet,代码和配置路径都没问题,HttpServlet居然报错 ...

  9. Ruby数组

    Ruby数组是有序的,任何对象的整数索引的集合.每个数组中的元素相关联,并提取到的一个索引.下标与C或Java相似,从0开始.负数索引假设数组末尾,也就是说-1表示最后一个元素的数组索引,-2是数组中 ...

  10. Idea 快捷键

    Ctrl+Alt+T 选中代码块加try catch等常用快捷操作.如图: psvm+Tab键 快速创建main方法 pout+Tab键 快速打出System.out.println(); Ctrl+ ...