SQL Federation 实验


第一步,创建表

CREATE DATABASE SalesDB
GO

第二步,连接到SalesDB,创建Federation
--
CREATE FEDERATION CustomerFederation(cid BIGINT RANGE)
GO
-- Connect to the federation member
USE FEDERATION CustomerFederation(cid = 0) WITH FILTERING=OFF, RESET
GO
CREATE TABLE [dbo].[Customer](
	[CustomerID] [bigint] NOT NULL,
	[Title] [nvarchar](18) NULL
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ([CustomerID] ASC) 
) FEDERATED ON (cid = CustomerID)
GO
CREATE TABLE [dbo].[CustomerAddress](
	[AddressID] [int] NOT NULL,
	[CustomerID] [bigint] NOT NULL,
	[AddressName]  [nvarchar](80) NULL
 	CONSTRAINT [PK_CustomerAddress] PRIMARY KEY CLUSTERED ([CustomerID],[AddressID] ASC)
) FEDERATED ON (cid = CustomerID)
GO
CREATE TABLE [dbo].[PostalCode](
	[PostalCodeID] [int] NOT NULL,
	[PostalCode] [nvarchar](15) NOT NULL
	 CONSTRAINT [PK_PostalCode] PRIMARY KEY CLUSTERED ([PostalCodeID] ASC)
)
GO

第三步,写入数据
USE FEDERATION CustomerFederation(cid = 0) WITH FILTERING=OFF, RESET
GO
Insert into [Customer](CustomerID,Title) values(999,'Symbio')
Insert into [Customer](CustomerID,Title) values(1000,'MS')
Insert into [Customer](CustomerID,Title) values(1001,'ABB1')
GO
Insert into [CustomerAddress]([AddressID],[CustomerID],[AddressName])   values(1,999,'Symbio Address')
Insert into [CustomerAddress]([AddressID],[CustomerID],[AddressName])   values(2,1000,'MS Address')
Insert into [CustomerAddress]([AddressID],[CustomerID],[AddressName])   values(3,1001,'ABB1 Address')
GO
Insert into [PostalCode]([PostalCodeID],[PostalCode])  values(1,'95568')
Insert into [PostalCode]([PostalCodeID],[PostalCode])  values(2,'95569')
Insert into [PostalCode]([PostalCodeID],[PostalCode])  values(3,'95570')


第四步,拆分,连接到主库SalesDB
GO
ALTER FEDERATION CustomerFederation SPLIT AT(cid = 1000)


第五步,验证

USE FEDERATION CustomerFederation(cid = 999) WITH RESET, FILTERING=on
GO


select * from [Customer]
select * from [CustomerAddress]
select * from [PostalCode]



阅读更多
个人分类: 云计算Azure
上一篇TechEd 2012 基于Windows Azure, 开发Windows 8及移动应用PPT
下一篇Building Multi-Tenant SaaS Applications on Azure
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭