Arnab's Blog

Always seeking for new technology

Create transactional publication in sql server 2008


Hi all,
Today we are going to learn how to create a transactional publication in sql server 2008. You may create it by using gui of sql server management studio. But we learn using sql script. Just copy the following code and enjoy…

exec sp_replicationdboption @dbname = N'testdb', @optname = N'publish', @value = N'true'

exec sp_addlogreader_agent @job_login = null, @job_password = null, @publisher_security_mode = 1

exec sp_addpublication
@publication = N'publication_name',
@description = N'Transactional publication of database ''testdb'' from publisher ''hasib\sql2008''. ',
@sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true',
@allow_annonymous = N'true', @enabled_for_internet = N'false',
@snapshot_in_defalultfolder = 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', @replicated_ddl = 1,
@allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false',
@enabled_for_het_sub = N'false'

exec sp_addpublication_snapshot
@publication = N'publication_name', @frequency_type = 0, @frequency_interval = 1,
@frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday =0,
@frequency_subday_interval = 1, @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

go

declare @name nvarchar(50)
declare curname cursor for
select name from sysobjects where type = 'U'
open curname
fetch next from curname into @name
while @@FETCH_STATUS = 0
begin
if exists(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name AND TABLE_SCHEMA = 'dbo')
begin
exec sp_addarticle
@publication = N'publication_name', @article = @name, @source_owner = N'dbo',
@source_object = @name, @type = N'logbased', @description = null, @creation_script = null,
@pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'manual', @destination_table = @name,
@destination_owner = N'dbo', @vertical_partition = N''
end
fetch next from curname into @name
end
close curname
deallocate curname

Thats all.

Bye

About these ads

3 Responses to Create transactional publication in sql server 2008

  1. Pingback: Create transactional publication in sql server 2008 « DbRunas – Noticias y Recursos sobre Bases de Datos

  2. Santos Sarafian December 3, 2012 at 7:14 am

    Hey there my name is Jill and I’m a student and this site really helped me. I’m inspired! Thank you!

  3. Sandy Sara December 5, 2012 at 8:40 am

    it’s wonderful.
    I wanna do it for several days.
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

SQL Server Journey with SQL Authority

Personal Notes of Pinal Dave

Șic și clasic - "Chic & Classic" luxury fine arts, handmade work, original design

Cand cumperi arta nu cumperi doar ceea ce vezi si pipai cumperi sufletul unui om, sufletul artistului pentru ca el/ artistul s-a uitat in sufletul lui si a scos de acolo ce a gasit

A passion for Small Business

Small Business is Big Business™

geekpython

skilled with python

Follow

Get every new post delivered to your Inbox.