SQL Server创建分布式数据库
作者:网络转载 发布时间:[ 2016/7/15 11:15:45 ] 推荐标签:数据库 SQL Server
step4,创建分布式水平分区视图
create view dbo.view_Person
as
select [PersonID]
,[PersonType]
,[FirstName]
,[MiddleName]
,[LastName]
from [dbo].[Person] with(nolock)
where [PersonType] in('IN','EM','SP')
union all
select [PersonID]
,[PersonType]
,[FirstName]
,[MiddleName]
,[LastName]
from db1.[DBTest2].[dbo].[Person] with(nolock)
where [PersonType] in('SC','VC','GC')
with check OPTION;
Step5,查询分布式数据,查看执行计划
SELECT *
from dbo.view_Person p
where p.PersonType in ('em','sc')
Step6,优化
分布式事务使用的资源远大于内部事务,通常使用OPENQUERY等相关行集函数,避免过度依赖分布式事务。
1,使用OpenQuery,避免DTC的干预
create view dbo.view_Person
as
select [PersonID]
,[PersonType]
,[FirstName]
,[MiddleName]
,[LastName]
from [dbo].[Person] with(nolock)
where [PersonType] in('IN','EM','SP')
union all
select [PersonID]
,[PersonType]
,[FirstName]
,[MiddleName]
,[LastName]
from OPENQUERY ( db1 ,
N'select [PersonID]
,[PersonType]
,[FirstName]
,[MiddleName]
,[LastName]
from db1.[DBTest2].[dbo].[Person] with(nolock)
where [PersonType] in(''SC'',''VC'',''GC'')' ) as p
with check OPTION;
2,在Local Server上更新分片数据
update db1.DBTEST2.dbo.person
set FirstName=N'Harm'
where PersonId=102;
--修改成
exec db1.DBTEST2.sys.sp_executesql N'update dbo.person
set FirstName=N''Harm''
where PersonId=102;'
Appendix
--SQL Server 阻止了对组件 'Ad Hoc Distributed Queries'
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
远程连接sql server 2000服务器的解决方案SQL Server修改数据库物理文件存在位置探讨SQL Server并发处理队列数据不阻塞解决方案迁移SQL Server到Azure SQL实战SQL SERVER 的前世今生?各版本功能对比SQL Server的WITH (NOLOCK)SQL Server如何用触发器捕获DML操作的会话信息SQL Server里书签查找的性能伤害监控SQL Server事务复制SQL Server数据库镜像下有效的索引维护SQL Server不停机移动镜像数据库SQL Server数据库备份压缩拷贝实例SQL Server数据库优化SQL SERVER的统计信息SQL Server里如何处理死锁SQL SERVER批量生成编号

sales@spasvo.com