The following procedures sp_MSdel, sp_MSins, sp_MSupd are the outcome of an configured publication/subscription on SQL Server.
These procedures let you do small transformations inside them so the streamed data can be transferred or reach the destination in different schema.
For instance having a publication for a table called "Data" with two columns into a publisher:
CREATE TABLE [dbo].[Data](
[id] [int] NOT NULL,
[description] [nchar](10) NULL,
CONSTRAINT [PK_Dasta] PRIMARY KEY CLUSTERED ([id] ASC) ON [PRIMARY]
)
I can have a little bit different structure for a table called "Data" with three columns into a subscriber:
CREATE TABLE [dbo].[Data](
[tenant_id] NOT NULL,
[id] [int] NOT NULL,
[description] [nchar](10) NULL,
CONSTRAINT [PK_Dasta] PRIMARY KEY CLUSTERED ([tenant_id] ASC, [id] ASC) ON [PRIMARY]
)
While doing this I can also modify the replication procedure [dbo].[sp_MSins_dboData] to add logic in this new destination column tenant_id
ALTER procedure [dbo].[sp_MSins_dboData]
@c1 int,
@c2 nchar(10)
as
begin
insert into [dbo].[Data] (
[tenant_id],
[id],
[description],
) values (
1,
@c1,
@c2)
Now in a scenario where there are multiple publishers pointing to the same subscription, is it possible to pass a parameter of origin (so instead of the hardcoded one to make it variable) to make sure of which origin are the streamed data?
I suppose the easiest solution is to create different procedures for each source database like sp_MSins_dboData_1, sp_MSins_dboData_2 etc but I was thinking for something more dynamic.
Any ideas?