原文 基于Sql Server 2008的分布式数据库的实践(四)

数据库设计

1.E-R图

2.数据库创建

Win 7

1
create database V3

  

Win 2003

1
create database V3

  

3.数据表设计

Win7 创建数据表student_7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
create table student_7
(
    sid int not null,
    sex nvarchar(1) not null,
    sname varchar(20) not null,
    school varchar(20) not null,
    scount varchar(20) not null,
    spwd varchar(20) not null,
    constraint pk_student_7
    primary key(sid,sex),
    constraint uq_student_7_scount
    unique(scount),
    constraint chk_student_7_sex
    check(sex='1')
)

Check(sex=1)指明存放sex=1的数据,即女生。

Win2003 创建数据表student_2003

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
create table student_2003
(
    sid int not null,
    sex nvarchar(1) not null,
    sname varchar(20) not null,
    school varchar(20) not null,
    scount varchar(20) not null,
    spwd varchar(20) not null,
    constraint pk_student_2003
    primary key(sid,sex),
    constraint uq_student_2003_scount
    unique(scount),
    constraint chk_student_2003_sex
    check(sex='0')
)

Check(sex=0)指明存放sex=0的数据,即男生。

Win7 创建视图V3_student

1
2
3
4
5
create view V3_student
as
select * from student_7
union all
select * from [192.168.116.130].[V3].[dbo].[student_2003]

Win2003 创建视图V3_student

1
2
3
4
5
create view V3_student
as
select * from student_2003
union all
select * from [192.168.233.1].[V3].[dbo].[student_7]

student水平分片数据表已经建立,现在可以在任何位置,只要访问本地V3_student分布式分区视图,就实现了所有分布式数据库的操作。此时,对数据库的全局操作和局部操作就如同操作本地集中式数据库一样。

-----------------------------------------------------------------------------------------------------------------

Win7创建数据表teacher

1
2
3
4
5
6
7
8
9
10
11
12
create table teacher
(
    tid int not null,
    tname varchar(20) not null,
tage int not null,
tsex int not null,
    tcount varchar(20) not null,
    tpwd varchar(20) not null,
tsuper int not null,
    primary key(tid),
    unique(tcount)
)

Win2003创建数据表teacher

1
2
3
4
5
6
7
8
create table teacher
(
    tid int not null,
nowage int not null,
tel char(20) not null,
address varchar(80) not null,
    primary key(tid)
)

Win7 创建存储过程V3_teacher

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
create proc V3_teacher
(
@tid int,
@tname varchar(20),
@tage int,
@tsex int,
@tcount varchar(20),
@tpwd varchar(20),
@super int,
@nowage int ,
@tel char(20) ,
@address varchar(80)
)
as
set XACT_ABORT on
BEGIN DISTRIBUTED TRANSACTION
insert into teacher
values(@tid,@tname,@tage,@tsex,@tcount,@tpwd,@super);
insert into [192.168.116.130].[V3].[dbo].[teacher]
values(@tid,@nowage,@tel,@address);
COMMIT TRANSACTION

采用存储过程实现垂直分片。此时插入数据之后,将分别插入到不同地址上的SQL Serverteacher的数据表里面。

-----------------------------------------------------------------------------------------------------------------

Win7创建数据表class

1
2
3
4
5
6
7
8
9
create table class
(
    cid int not null,
    sid int not null,
tid int not null,
cname varchar(20) not null,
    score int not null,
    primary key(cid,sid)
)

本地数据表。

-----------------------------------------------------------------------------------------------------------------

Win 7:

Win2003:

4.程序代码测试

水平分片测试

垂直分片测试

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3459836.html

基于Sql Server 2008的分布式数据库的实践(四)的更多相关文章

  1. 基于Sql Server 2008的分布式数据库的实践(五)

    原文 基于Sql Server 2008的分布式数据库的实践(五) 程序设计 ------------------------------------------------------------- ...

  2. 基于Sql Server 2008的分布式数据库的实践(三)

    原文 基于Sql Server 2008的分布式数据库的实践(三) 配置PHP 1.打开PHP配置文件,找到extension=php_mssql.dll,将前面的注释符号去掉 2.找到mssql.s ...

  3. 基于Sql Server 2008的分布式数据库的实践(二)

    原文 基于Sql Server 2008的分布式数据库的实践(二) 从Win7连接Win2003的Sql Server 2008 1.新建链接服务器链接到Win2003的Sql Server 2008 ...

  4. 基于Sql Server 2008的分布式数据库的实践(一)

    原文 基于Sql Server 2008的分布式数据库的实践(一) 配置Sql Server 2008(Win7) 1.打开SQL server2012,使用windows身份登录 2.登录后,右键选 ...

  5. 基于Sql Server 2008的分布式数据库的实践(终结)

    学习.操作心得 以前在做网站程序的时候一直用的是MYSQL,但是网上搜到MYSQL不支持分布式操作,然后便开始查询MSSQL的分布式数据库的设计与操作,后来在网上找到了<基于SQL SERVER ...

  6. 基于Sql Server 2008的分布式数据库的实践

    配置Sql Server 2008(Win7) 1.打开SQL server2012,使用windows身份登录 2.登录后,右键选择“属性”.左侧选择“安全性”,选中右侧的“SQL Server 和 ...

  7. 基于SQL Server 2008 Service Broker构建企业级消息系统

    注:这篇文章是为InfoQ 中文站而写,文章的地址是:http://www.infoq.com/cn/articles/enterprisemessage-sqlserver-servicebroke ...

  8. SQL SERVER 2008 R2 还原数据库3154错误

    1.SQL SERVER 2008 在还原数据库时,会报错. 提示错误:"备份集中的数据库备份与现有的 '***' 数据库不同.RESTORE DATABASE 正在异常终止. (Micro ...

  9. SQL Server 2008 R2 主从数据库同步

    一.准备工作: 主数据库服务器: OS:Windows Server 2008 R2    DB: SQL Server 2008 R2 Hostname : CXMasterDB IP: 192.1 ...

随机推荐

  1. Xvfb+YSlow+ShowSlow搭建前端性能测试框架 - 前端技术 | TaoBaoUED

    Xvfb+YSlow+ShowSlow搭建前端性能测试框架 - 前端技术 | TaoBaoUED Xvfb+YSlow+ShowSlow搭建前端性能测试框架 作者:黑三 | 时间:2010-07-07 ...

  2. android使用全局变量的两种方法

         在我们使用android编写程序的时候,少不了想利用全局变量,但是面向对象语言和过程语言区别很大,不再是include就可以的.这里我写了使用全局变量的两种方法: 1.使用applicati ...

  3. Romantic(裸扩展欧几里德)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. Linux相关问题-CentOS6.5 x64版本号下Tomcat无法自启动的解决的方法

    前段时间使用阿里云server.使用的是Linux CentOS6.5系统,在搭建完Tomcat后发现,Tomcat无法自启动. 将启动tomcat的命令为tomcat_home/bin/startu ...

  5. Objective-c 类的继承 方法重写 方法重载

    一.类的继承 Objective-c中类的继承与C++类似,不同的是Objective-c不支持多重继承,一个类只能有一个父类,单继承使Objective-c的继承关系很简单,易于管理程序. Obje ...

  6. Enze Second day

    哈喽,很高兴在云和学院又学了一天的新知识,现在,我来继续总结一下今天所学的以及对昨天的一些补充. 变量 • 声明变量的语法格式: –数据类型  变量名; •赋值:     变量名=值; 变量的命名 • ...

  7. 【ActiveMQ】设置自动重连

    <property name="brokerURL" value="tcp://localhost:61616"/> <property na ...

  8. Java调用Oracle存储Package

    Oracle的包Package中可以有很多存储,可通过该包的总调入口在java中直接调用. //java调用oracle的package代码 public boolean cal() throws j ...

  9. codeforces 463E . Caisa and Tree

    题目链接 给一棵树, 两种操作, 一种是将点u的权值改为y, 另一种是查询根节点到点u的路径上, gcd(v, u)>1的深度最深的点v. 修改操作不超过50次. 这个题, 暴力可以过, 但是在 ...

  10. python成长之路13

    一:SqlAlchemy ORM ORM:Object Relational Mapping 对象关系映射是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 SQLAlchemy是 ...