If you have completed the entire stage of transactional replication using SSMS, then this is not difficult to do with the script.
Just carefully note that when setting up mailing, publishing and subscribing, SSMS gives you the ability to generate a script at every step.
You can use the generated script.
But the only difference is adding articles to the publication. You can use the following code to add an article.
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
Or you can see https://hasibarnab.wordpress.com/category/sql-server/replication/
source share