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

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介: 原文 基于Sql Server 2008的分布式数据库的实践(四) 数据库设计 1.E-R图 2.数据库创建 Win 7 1 create database V3    Win 2003 1 create database V3    3.

原文 基于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语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
3天前
|
SQL Oracle 关系型数据库
sql语句创建数据库
在创建数据库之前,请确保你有足够的权限,并且已经考虑了数据库的安全性和性能需求。此外,不同的DBMS可能有特定的最佳实践和配置要求,因此建议查阅相关DBMS的官方文档以获取更详细和准确的信息。
|
14天前
|
SQL 算法 数据库
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
84 6
|
1天前
|
SQL 数据管理 关系型数据库
如何在 Windows 上安装 SQL Server,保姆级教程来了!
在Windows上安装SQL Server的详细步骤包括:从官方下载安装程序(如Developer版),选择自定义安装,指定安装位置(非C盘),接受许可条款,选中Microsoft更新,忽略警告,取消“适用于SQL Server的Azure”选项,仅勾选必要功能(不包括Analysis Services)并更改实例目录至非C盘,选择默认实例和Windows身份验证模式,添加当前用户,最后点击安装并等待完成。安装成功后关闭窗口。后续文章将介绍SSMS的安装。
4 0
|
2天前
|
SQL Java 数据库连接
Java从入门到精通:2.3.2数据库编程——了解SQL语言,编写基本查询语句
Java从入门到精通:2.3.2数据库编程——了解SQL语言,编写基本查询语句
|
2天前
|
SQL 关系型数据库 MySQL
:“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi
:“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi
10 0
|
3天前
|
SQL 缓存 数据库
sql 数据库优化
SQL数据库优化是一个复杂且关键的过程,涉及多个层面的技术和策略。以下是一些主要的优化建议: 查询语句优化: 避免全表扫描:在查询时,尽量使用索引来减少全表扫描,提高查询速度。 使用合适的子查询方式:子查询可能降低查询效率,但可以通过优化子查询的结构或使用连接(JOIN)替代子查询来提高性能。 简化查询语句:避免不必要的复杂查询,尽量使SQL语句简单明了。 使用EXISTS替代IN:在查询数据是否存在时,使用EXISTS通常比IN更快。 索引优化: 建立合适的索引:对于经常查询的列,如主键和外键,应创建相应的索引。同时,考虑使用覆盖索引来进一步提高性能。 避免过多的索引:虽然索引可以提高查询
|
3天前
|
SQL XML 数据库
sql导入数据库命令
在SQL Server中,数据库导入可通过多种方式实现:1) 使用SSMS的“导入数据”向导从各种源(如Excel、CSV)导入;2) BULK INSERT语句适用于导入文本文件;3) bcp命令行工具进行批量数据交换;4) OPENROWSET函数直接从外部数据源(如Excel)插入数据。在操作前,请记得备份数据库,并可能需对数据进行预处理以符合SQL Server要求。注意不同方法可能依版本和配置而异。
|
7天前
|
SQL 自然语言处理 数据库
NL2SQL实践系列(2):2024最新模型实战效果(Chat2DB-GLM、书生·浦语2、InternLM2-SQL等)以及工业级案例教学
NL2SQL实践系列(2):2024最新模型实战效果(Chat2DB-GLM、书生·浦语2、InternLM2-SQL等)以及工业级案例教学
NL2SQL实践系列(2):2024最新模型实战效果(Chat2DB-GLM、书生·浦语2、InternLM2-SQL等)以及工业级案例教学
|
10天前
|
SQL 安全 网络安全
IDEA DataGrip连接sqlserver 提示驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接的解决方法
IDEA DataGrip连接sqlserver 提示驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接的解决方法
20 0
|
10天前
|
SQL 自然语言处理 测试技术
NL2SQL进阶系列(4):ConvAI、DIN-SQL等16个业界开源应用实践详解[Text2SQL]
NL2SQL进阶系列(4):ConvAI、DIN-SQL等16个业界开源应用实践详解[Text2SQL]
NL2SQL进阶系列(4):ConvAI、DIN-SQL等16个业界开源应用实践详解[Text2SQL]

热门文章

最新文章