-- 启用复制数据库
use master
exec sp_replicationdboption @dbname = N'room', @optname = N'publish', @value = N'true'
GO
use master
exec sp_replicationdboption @dbname = N'room', @optname = N'publish', @value = N'true'
GO
exec [room].sys.sp_addlogreader_agent @job_login = null, @job_password = null, @publisher_security_mode = 1
GO
-- 添加事务发布
use [room]
exec sp_addpublication @publication = N'pub_roomSync', @description = N'来自发布服务器“DB_DEVELOP\DEVELOP04”的数据库“room”的事务发布。', @sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'false', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'false', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO
GO
-- 添加事务发布
use [room]
exec sp_addpublication @publication = N'pub_roomSync', @description = N'来自发布服务器“DB_DEVELOP\DEVELOP04”的数据库“room”的事务发布。', @sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'false', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'false', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO
exec sp_addpublication_snapshot @publication = N'pub_roomSync', @frequency_type = 1, @frequency_interval = 0, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 0, @frequency_subday_interval = 0, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = null, @job_password = null, @publisher_security_mode = 1
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'sa'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'XIU88\administrator'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'NT SERVICE\Winmgmt'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'NT SERVICE\SQLWriter'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'NT Service\MSSQL$DEVELOP04'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'NT SERVICE\SQLAgent$DEVELOP04'
GO
exec sp_grant_publication_access @publication = N'pub_roomSync', @login = N'distributor_admin'
GO
-- 添加事务项目
use [room]
exec sp_addarticle @publication = N'pub_roomSync', @article = N'live_info', @source_owner = N'dbo', @source_object = N'live_info', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F, @identityrangemanagementoption = N'none', @destination_table = N'live_info', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dbolive_info]', @del_cmd = N'CALL [sp_MSdel_dbolive_info]', @upd_cmd = N'SCALL [sp_MSupd_dbolive_info]'
GO
use [room]
exec sp_addarticle @publication = N'pub_roomSync', @article = N'live_info', @source_owner = N'dbo', @source_object = N'live_info', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F, @identityrangemanagementoption = N'none', @destination_table = N'live_info', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dbolive_info]', @del_cmd = N'CALL [sp_MSdel_dbolive_info]', @upd_cmd = N'SCALL [sp_MSupd_dbolive_info]'
GO
-- 添加事务订阅
use [room]
exec sp_addsubscription @publication = N'pub_roomSync', @subscriber = N'DB_DEVELOP\DEVELOP07', @destination_db = N'user01', @subscription_type = N'Push', @sync_type = N'automatic', @article = N'all', @update_mode = N'read only', @subscriber_type = 0
exec sp_addpushsubscription_agent @publication = N'pub_roomSync', @subscriber = N'DB_DEVELOP\DEVELOP07', @subscriber_db = N'user01', @job_login = null, @job_password = null, @subscriber_security_mode = 1, @frequency_type = 64, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 4, @frequency_subday_interval = 5, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @dts_package_location = N'Distributor'
GO