分布式数据库的四分结构设计 BCDE
首先,对关系型数据库的表进行四种分类定义:
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的更多相关文章
- SDP(6):分布式数据库运算环境- Cassandra-Engine
现代信息系统应该是避不开大数据处理的.作为一个通用的系统集成工具也必须具备大数据存储和读取能力.cassandra是一种分布式的数据库,具备了分布式数据库高可用性(high-availability) ...
- 开源分布式数据库中间件MyCat源码分析系列
MyCat是当下很火的开源分布式数据库中间件,特意花费了一些精力研究其实现方式与内部机制,在此针对某些较为重要的源码进行粗浅的分析,希望与感兴趣的朋友交流探讨. 本源码分析系列主要针对代码实现,配置. ...
- erlang 分布式数据库Mnesia 实现及应用
先推荐一篇:mnesia源码分析(yufeng) - linear hash ETS/DETS/mnesia 都使用了linear hash算法 http://en.wikipedia.org ...
- 分布式数据库中的Paxos 算法
分布式数据库中的Paxos 算法 http://baike.baidu.com/link?url=ChmfvtXRZQl7X1VmRU6ypsmZ4b4MbQX1pelw_VenRLnFpq7rMvY ...
- Distributed4:SQL Server 分布式数据库性能测试
我使用三台SQL Server 2012 搭建分布式数据库,将一年的1.4亿条数据大致均匀存储在这三台Server中,每台Server 存储4个月的数据,Physical Server的配置基本相同, ...
- Distributed3:SQL Server 创建分布式数据库
分布式数据库的优势是将IO分散在不同的Physical Disk上,每次查询都由多台Server的CPU,I/O共同负载,通过各节点并行处理数据来提高性能,劣势是消耗大量的网络带宽资源,管理难度大.在 ...
- 【Java EE 学习 30】【闪回】【导入导出】【管理用户安全】【分布式数据库】【数据字典】【方案】
一.闪回 1.可能的误操作 (1)错误的删除了记录 (2)错误的删除了表 (3)查询历史记录 (4)撤销已经提交了的事务. 2.对应着以上四种类型的误操作,有四种闪回类型 (1)闪回表:将表回退到过去 ...
- 云时代的分布式数据库:阿里分布式数据库服务DRDS
发表于2015-07-15 21:47| 10943次阅读| 来源<程序员>杂志| 27 条评论| 作者王晶昱 <程序员>杂志数据库DRDS分布式沈询 摘要:伴随着系统性能.成 ...
- SQL Server分布式数据库技术(LinkedServer,CT,SSB)
SQL Server自定义业务功能的数据同步 在不同业务需求的驱动下,数据库的模块化拆分将会面临一些比较特殊的业务逻辑处理需求.例如,在数据库层面的数据同步需求.同步过程中,可能会有一些比较复杂的业务 ...
随机推荐
- mysql中的行转列
//查看当前商品库存 function checkProductStock($product_id){ global $wpdb; $sql="SELECT post_id,max(if(( ...
- optparse
Python 有两个内建的模块用于处理命令行参数: 一个是 getopt,<Deep in python>一书中也有提到,只能简单处理 命令行参数: 另一个是 optparse,它功能强大 ...
- Python: Windows 7 64位 安装、使用 pymongo 3.2
官网tutorial: http://api.mongodb.com/python/current/tutorial.html 本教程将要告诉你如何使用pymongo模块来操作MongoDB数据库. ...
- theano学习
import numpy import theano.tensor as T from theano import function x = T.dscalar('x') y = T.dscalar( ...
- Oracle10g 表分区
1.分区的原因 (1)Tables greater than 2GB should always be considered for partitioning. (2)Tables containin ...
- java中Inetaddress类
InetAddress类 InetAddress类用来封装我们前面讨论的数字式的IP地址和该地址的域名. 你通过一个IP主机名与这个类发生作用,IP主机名比它的IP地址用起来更简便更容易理解. Ine ...
- MS Sql Server
# 安装SQL2000时总是提示:以前的某个程序安装已经在安装计算机上创建挂起的文件操作 原文:https://zhidao.baidu.com/question/424367402.html # S ...
- Swagger(webapi自动生成接口说明文档)
1.引入Swagger.Net.UI和Swashbuckle包 2.卸载重复包Swagger.Net 3.多余的SwaggerUI文件夹 4.项目属性->勾选生成xml文档文件 5.添加类Swa ...
- JS模块化
一.原始写法 /* 模块就是实现特定功能的一组方法. 只要把不同的函数(以及记录状态的变量)简单地放在一起,就算是一个模块. 上面的函数m1()和m2(),组成一个模块.使用的时候,直接调用就行了. ...
- wkhtmltopdf 将网页转换为PDF和图片
wkhtmltopdf 是一个shell工具,它使用了WebKit渲染引擎和Qt,将网页html转换为pdf的强大工具,转换后的pdf也可以通过pdf工具进行复制.备注.修改 官网下载地址:http: ...