Sei sulla pagina 1di 49

SqlServer

Sqlserver

Microsoft Sql Server 2000

Microsoft Sql Server 2000 Replication


Database Object Data
Data
Data Consistency Synchronizing
Database

Intranet Internet

Application Performance
WEB

Replication

OLTP Application
OLAP Application

Server
Server Server

Performance

Database
Fail
Replication

Application Server
Performance
Replication Application

Data Replication

Data
Server
Replication
Data

Offline Online Application

Data Web Application


Data Browse

Replication

Replication Replication

Article Article
View Store Procedure
Data Article Database
Replication Database Object

Article Publication Publication


Object Article . Database
Replication Database

Data : Publisher
Publication Publisher
Data
Publisher
Data Publication

Distributor Distributor
Data Data Database
Database Metadata Transaction
Replication Distributor
Distributor
Publisher
Subscription Subscription
Replication
Publication Subscription

Publication Subscription

Data Server Subscribers


Publication Subscriber

Microsoft MSqlServer 2000 Replication Model

agent Replication
Merge Replication Agent
Agent Monitor

Merge Replication
Merge Agent

Replication Agent SqlServer Agent


agent Agent
Job Replication

Agent Replication Agent Snapshot Agent


Publish Schema
Distributed Database

Agent Merge Replication Merge Agent


( Subscriber Snapshot
agent Subscriber Publisher
Upload Publisher
Download

Agent Agent
agent

agent

Distributor Agent History Clean Up

Distribution Transaction Distribution Clean Up

Publisher Subscriber Expired Subscription Clean Up


Publisher
Reinitialize Subscriptions Having Data Validation Failures
Validation Subscriber
Replication Agent Replication Agents Checkup
Replication Monitor

Log Replication Agent


Enterprise Manager Replication Monitor Replication

Replication Agent Replication


Replication

Business Objective and Requirements

Replication
Replication

Data Modification Distribution Data

Data Distribution
Replication

Data o
Data Replication
Update Application
Online Offline Data

Data o

Data
Data Data o
Data
Data o
Refresh Data o
Updating
o

Subscriber Publish Data o

Subscriber o
Data o

Data Modification
Replication Data
Option

Update Subscriber o
Conflict Update Subscriber o

Data Subscriber Data o

Publisher Connection Subscriber o


Update o
Handle Conflict
o
Subscriber Initial snapshot o
Database

Data
Publisher subscriber

subscriber Distributer Publisher

Agent Profiler
polling interval buffer Replication
Replication time out expire
Performance

Replication APP

Conflict APP
Update subscriber
“Partitioning Conflict
Merge Conflict Replication APP
Conflict Merge Replication Replication

Conflict Replication

Offline
Publisher

Sequence

Insert
Replication Replication

Image Text Merge Replication


Merge Replication
Replication

Data Type

Replication Data Type

Time Stamp
Time Stamp
Replication

Uniqueidentifier
Merge Replication
Replication Publish

Replication

Image Text
Merge Replication Data
Publisher Replication

Trigger
Publish Publication Trigger
Trigger Publish
Merge Replication

Data Merge Replication


Data Offline, OnLine
Subscriber
Database
Subscriber Publisher SqlServer
Data Merge agent
Conflict

Merge Replication

Data

Offline Data
Data App

Transactional Application

Merge Replication

: Data Integrity
subscriber Data Subscriber Data
Subscriber App
Subscriber Publisher

Application Publish

Foreign Key
article Publication
Reference
Replication Publication Master
Replication

Option SqlServer Bug


Conflict Detection and resolution
Merge Replication
Replication Conflict Conflict
Replication Conflict
Option Conflict
Conflict

Subscriber Update Publisher o


Update
Update
Subscriber Publisher o

Trigger and business rules


Constraint Trigger Replication
Constraint Trigger
Loop Replication
Not For Replication Option
Replication

Text and image Data type


Image Text Merge Replication
Writetext Image Text
Updatetext
Update
Merge Replication

Database

Replication
Primary Key
rowguid
Replication
Select View
CD
Unique Index

rowguid uniqueidentifier ROWGUIDCOL NOT NULL DEFAULT Newid()

CREATE UNIQUE INDEX [ index_1977058079] ON [ dbo].[PART]([rowguid])

CD
Rowguid CD
Index

Sequence Primary Key


Range

Publisher :PartCode Sequence 1..1000000

Subscriber: Partcode Sequence 1000001..2000000

conflict
HighIdGen LowIDGen MIS
TableIdGen
Unique Constraint
Range
Duplicate

Database
Reference

Replication

Unit Replication Part


Replication
Enforce relationship for replication Option Reset
Replication Master Unit

Master Data Subscriber o


Reference
Detail Replication o
Conflict Conflict Master
Reset Option
SqlServer Work Letter

Database
Replication

Replication

Trigger Summary
Replication
Trigger Replication Summary
Replication Trigger

NOT FOR REPLICATION


Replication Option
MIS Identity
Trigger
Trigger

Trigger
Trigger Publication
Option
Publication Trigger
Trigger Option
Replication Publication
Publication
Data Replication LOOP

Merge Replication Publisher

Replication

Subscription Publication

Script Script

SQLSERVER SQL Server Enterprise Manager


local Register
Control Panel-> Administrative Tools-> Services
Account Startup SqlServerAgent
Administrator LogOn
Password

manage publications… tools-> Replication-> Create and


Button Database
Create Publication

Option
. NEXT
Distributed Database Server

Distributor Publisher Performance


Snapshot
Subscriber Share
Pull Subscriber Push Subscriber
Subscriber Pull Subscriber
Database
Next

Publisher
Next sgdb
merge
Next merge
Subscriber
Next

GNR.CRSPND
owner Destination table owner

Script Script Publisher


Next
ROWGUID Publisher
Database
publisher Publication name
Publication Description Publisher

test publisher

Filtering Option
Condition Option
Database
Publisher Finish

publisher

Publisher o
Publisher Distributor o
Publication Publisher o
Log Trigger
sql server Replication monitor o
Replication
Agent job o
sql server job
Snapshot Agent Publisher o
Agent

Replication Monitor Snapshot

Publisher RowGuid
Publisher Database
SqlServer Bug Subscriber
View Backup Owner
Refresh StoreProcedure

Refresh Views o

View sp_refreshview
Results in text Query Query Analyzer

select 'sp_refreshview ' + ''''+ u.name + '.' + o.Name + '''' + char(13) +'GO
from sysobjects o ,sysusers u where xtype= 'V' and
o.uid= u.uid

Query Analyzer
View
View

SP_Configure 'Allow updates',1


reconfigure with override

begin tran

select o.name n1 ,o1.name n2 , o.Uid u1,O1.Uid u2


Into # Temp2
from sysobjects o , sysobjects O1
where o.name like 'conflict_%' and o.name like '%'+ O1.name and o.name <>
O1.Name
and (len (o.name)- 10 - 4 = len(o1.name
order by O.name

test publisher

affected

affected)35 row(s

update sysobjects
set UId = o.u2
from # Temp2 O
where name = n1

Commit
Drop Table # Temp2

SP_Configure 'Allow updates',0


reconfigure with override

backup
serverconfig restore
restore

SP_Configure 'Allow updates',1


reconfigure with override

update sysobjects
set UId = 1
where name like 'conflict

SP_Configure 'Allow updates',0


reconfigure with override

publisher
SGDB
serverconfig restore
restore backup
conflict restore backup

subscriber

register

replication -> publication -> publisher name : database name


publisher properties
Merge Replication Subscriber

Restore Database Publisher Subscriber


Subscriber ServerConfig
Register Subscriber
Subscription

replication -> publication -> publisher name : Database name


publisher properties

Push New… subscriptions


subscriber wizard
NEXT Option

Next
Subscriber Database
Database Browse or create
NEXT
Merge Agent
job
Agent change
Connection

Connection

Data Agent
Database
Option Backup

Subscriber
Subscriber
Database
Replication
Replication RUN
publisher Subscriber FINISH
Data Replication

Publication monitor-> Publisher -> Computer name -> Publisher name:database


name
merge agent
no data neede to be merged

Merge AGENT
Step Agent
Agent JOB
Property Agent Property
Merge Replication Conflict

Merge Replication Conflict


Conflict
Replication Conflict

Replication Application Database


Replication
Replication
Conflict
Replication
Replication
Subscription

Conflict
Administrator Conflict

Conflict

Conflict
Conflict
Conflict Replication
conflict

Conflict

Database - > Database Name - > Publication -> publication Name


Replication Monitor - > Publishers - > Server Names - > publication Name
View Conflict Mouse

View Publisher
Conflict
Reinitialize all Publication
subscription
Reinitialize all subscription

New Publication
Database Publication
view offwork conflict
delete update
conflict

delete Resolver
resolver

resolver Keep winning change


update Resolve With This Data

conflict conflict Postpone resolution

resolver
Replication Application
conflict
Merge Replication Script

Replication Script
Replication

Schema Database Database


Script

Script Replication

Publication Pubs Database


Pubs2 Schema Database Authors
Subscription

Replication Script
Generate Sql Script
Publication Replication

Distribution Database Script o


Script Option Distributor Properties
Database
Script Database
Publication
o
: Publication Script o
Option Publication

Publisher distribution Component o


Publisher Component Drop Option Enable
Disable
Distributed Publication script
Subscriber
/****** Scripting the replication setup of server SAEED. Script Date: 2004/09/27
08:49:28 ******/
/****** Please note: Any password parameter was scripted with NULL or empty
string for security reason. ******/

/****** Begin: Script to be run at Distributor: SAEED ******/


/****** Installing the server SAEED as a Distributor. Script Date: 2004/09/27
08:49:28 ******/
use master
GO

exec sp_adddistributor @distributor = N'SAEED', @password = N''


GO

-- Updating the agent profile defaults


sp_MSupdate_agenttype_default @profile_id = 1
GO
sp_MSupdate_agenttype_default @profile_id = 2
GO
sp_MSupdate_agenttype_default @profile_id = 4
GO
sp_MSupdate_agenttype_default @profile_id = 6
GO
sp_MSupdate_agenttype_default @profile_id = 11
GO

-- Adding the distribution database


exec sp_adddistributiondb @database = N'distribution', @data_folder =
N'C:\ Program Files\ Microsoft SQL Server\ MSSQL\ Data', @data_file =
N'distribution.MDF', @data_file_size = 2, @log_folder = N'C:\ Program
Files\ Microsoft SQL Server\ MSSQL\ Data', @log_file = N'distribution.LDF',
@log_file_size = 0, @min_distretention = 0, @max_distretention = 72,
@history_retention = 48, @security_mode = 0, @login = N'sa', @password = null
GO

-- Adding the distribution publisher


exec sp_adddistpublisher @publisher = N'SAEED', @distribution_db =
N'distribution', @security_mode = 1, @working_directory =
N'\ \ SAEED\ C$\ Program Files\ Microsoft SQL Server\ MSSQL\ ReplData', @trusted =
N'false', @thirdparty_flag = 0
GO
/****** End: Script to be run at Distributor: SAEED ******/

/****** Begin: Script to be run at Publisher: SAEED ******/


-- Adding the registered subscriber
exec sp_addsubscriber @subscriber = N'SAEED', @type = 0, @login = N'sa',
@password = N'', @security_mode = 0, @frequency_type = 64,
@frequency_interval = 1, @frequency_relative_interval = 2,
@frequency_recurrence_factor = 0, @frequency_subday = 8,
@frequency_subday_interval = 1, @active_start_date = 0, @active_end_date = 0,
@active_start_time_of_day = 0, @active_end_time_of_day = 235900,
@description = N''
exec sp_changesubscriber_schedule @subscriber = N'SAEED', @agent_type = 1
GO

-- Enabling the replication database


use master
GO

exec sp_replicationdboption @dbname = N'pubs', @optname = N'merge publish',


@value = N'true'
GO

use [pubs]
GO

-- Adding the merge publication


exec sp_addmergepublication @publication = N'pubs', @description = N'Merge
publication of pubs database from Publisher SAEED.', @retention = 14,
@sync_mode = N'native', @allow_push = N'true', @allow_pull = N'true',
@allow_anonymous = N'false', @enabled_for_internet = N'false',
@centralized_conflicts = N'true', @dynamic_filters = N'false',
@snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port
= 21, @ftp_login = N'anonymous', @conflict_retention = 14,
@keep_partition_changes = N'false', @allow_subscription_copy = N'false',
@allow_synctoalternate = N'false', @add_to_active_directory = N'false',
@max_concurrent_merge = 0, @max_concurrent_dynamic_snapshots = 0
exec sp_addpublication_snapshot @publication = N'pubs',@frequency_type = 4,
@frequency_interval = 1, @frequency_relative_interval = 1,
@frequency_recurrence_factor = 0, @frequency_subday = 1,
@frequency_subday_interval = 5, @active_start_date = 0, @active_end_date = 0,
@active_start_time_of_day = 500, @active_end_time_of_day = 235959,
@snapshot_job_name = N'SAEED-pubs-pubs-1'
GO
exec sp_grant_publication_access @publication = N'pubs', @login =
N'BUILTIN\ Administrators'
GO
exec sp_grant_publication_access @publication = N'pubs', @login =
N'distributor_admin'
GO
exec sp_grant_publication_access @publication = N'pubs', @login = N'sa'
GO

-- Adding the merge articles


exec sp_addmergearticle @publication = N'pubs', @article = N'authors',
@source_owner = N'dbo', @source_object = N'authors', @type = N'table',
@description = null, @column_tracking = N'true', @pre_creation_cmd = N'drop',
@creation_script = null, @schema_option = 0x000000000000CFF1,
@article_resolver = null, @subset_filterclause = null, @vertical_partition =
N'false', @destination_owner = N'dbo', @auto_identity_range = N'false',
@verify_resolver_signature = 0, @allow_interactive_resolver = N'false',
@fast_multicol_updateproc = N'true', @check_permissions = 0
GO

-- Adding the merge subscription


exec sp_addmergesubscription @publication = N'pubs', @subscriber = N'SAEED',
@subscriber_db = N'pubs2', @subscription_type = N'push', @subscriber_type =
N'local', @subscription_priority = 0.000000, @sync_type = N'none',
@frequency_type = 4, @frequency_interval = 1, @frequency_relative_interval =
1, @frequency_recurrence_factor = 0, @frequency_subday = 8,
@frequency_subday_interval = 1, @active_start_date = 0, @active_end_date = 0,
@active_start_time_of_day = 0, @active_end_time_of_day = 235959,
@enabled_for_syncmgr = N'false', @offloadagent = 0, @use_interactive_resolver
= N'false'
GO

/****** End: Script to be run at Publisher: SAEED ******/


Merge Replication Replication

Subscriber

Subsriber

Subscriber Subscriber TAB


Delete

Publisher
Script SqlServer Bug Publisher
Enterprize Publisher
Delete Mouse Manger
Script
Trigger
Publisher Script
SP_Configure 'Allow updates',1
reconfigure with override

begin tran

select o.name n1 ,o1.name n2 , o.Uid u1,O1.Uid u2


Into # Temp2
from sysobjects o , sysobjects O1
where o.name like 'conflict_%' and o.name like '%'+ O1.name and o.name <>
O1.Name
and (len (o.name)- 10 - 4 = len(o1.name
order by O.name

test publisher

affected

affected)35 row(s

update sysobjects
set UId = o.u2
from # Temp2 O
where name = n1

Commit
Drop Table # Temp2

SP_Configure 'Allow updates',0


reconfigure with override

Publisher Script

Replication
sqlServer Replication
Publisher Bug
Disable …. Replication Tools
Replication
Publication Object

Article
article Store Procedure
Publication

sp_dropmergearticle [ @publication = ] 'publication'


, [ @article = ] 'article'
[ , [ @ignore_distributor = ] ignore_distributor
[ , [ @reserved = ] reserved
[ , [ @force_invalidate_snapshot = ] force_invalidate_snapshot ]

subscription Article
Article

Article

Publication article Store Procedure

exec sp_addmergearticle @publication = N'Rep1', @article = N't2',


@source_owner = N'dbo', @source_object = N't2', @type = N'table',
@description = null, @column_tracking = N'true', @pre_creation_cmd = N'drop',
@creation_script = null, @schema_option = 0x000000000000CFF1,
@article_resolver = null,
@subset_filterclause = null, @vertical_partition = N'false', @destination_owner =
N'dbo',
@auto_identity_range = N'false', @verify_resolver_signature = 0,
@allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true',
@check_permissions = 0
,@force_invalidate_snapshot = 1
Rep1 Publication T1
subscription Article
Article

Snapshot agent Article


Article

Type
Article Publication

Database Service Pack


Replication Article
Index Rowguid

Database Backup
Merge Replication)

RDBMS
Replication Database

Backup Replication Database


Database Backup
Replication Database

Publication Database

Publication Database o
SqlServer Bug
Script Owner
JOB
Step Publication Database
Backup Script

Publication Database o
Subscription Database Database
Script Publication Database Restore

Publication Database
Data Subscription Synchronization
Subscription
Subscriber Data
Publisher Publisher

Publisher Subscriber
Script Restore
Snapshot agent Database
Publisher Subscriber Reinitialize
Publication Database subscriber

Subscription Database
Database Publication Database
Restore Publisher
Initialization Synchronizing

Distribution Database
Publication Database
Database Distribution Database
Log Merge Replication

MSDB system database


SqlServer JOB Database
Database Replication Agent JOB
JOB
Subscriptor JOB
Database

Master Database
Master MSDB
Database Master Db
Server Replication
sysservers distribution
Database
Merge Replication) Replication

Replication

Replication

Publisher
Subscriber Publisher o
Subscriber distributor Publisher

Subscriber Publisher
Subscriber Publisher
Subscriber
Subscriber Filtering Data
Publisher
Remote Distributor Publisher
Distributor Publisher
Publisher
connection

Republishing

Publish Data
Publisher subscriber Publisher
connection Subscriber
Connection
Distributor

Subscriber
Data Publisher
Subscriber
Publisher Data

E-mail : SunLand_Info@Yahoo.com

Potrebbero piacerti anche