Trigger in subscriber is getting deleted when replication is created - sql-server-2000

I have a table A in publisher database and there is trigger which inserts data into table B when an entry happens in table A. I have the same configuration in subscriber database,
that is Table A, Table B and the trigger. I have done transactional replication for both the DB and after the establishing the replication, trigger in subscriber database is deleted. Please give me the reason why the trigger in subscriber is deleted when the replication is created.

Is your trigger created with the "NOT FOR REPLICATION" option?
Rob

Related

DML triggers in memory optimized table in SQL Server 2016

I have two tables: table 1 is disk based storage and table 2 is in memory storage. I create a DML trigger on table 2 and in that trigger, I insert a record into table 1. Will it be possible?
You can't, it's not possible in the same in-memory transaction using mvcc isolation access a disk-based table through the trigger.
For workaround this you could saving to a stage table memory-based inside the trigger and insert or update to table 1 from stage table using update-join between a memory-based-disk and table-based-disk although it cames with some admin to manage and control but works.
DDL Tiggers still doesn't work even SQL 2017.

Delete before delete trigger

I have two tables:
Table MASTER
Table SLAVE with a column ID that always matches a MASTER.ID
I would like to delete the SLAVE before deleting a MASTER through a DB2 trigger.
Here's what I wrote:
CREATE TRIGGER delete_slave
BEFORE DELETE ON MASTER
REFERENCING OLD AS o FOR EACH ROW
DELETE FROM SLAVE WHERE ID = o.ID;
When I execute the query on a DB2 V10.5.0.3 database I get the following error:
The trigger "SCHEMA1.DELETE_SLAVE" is defined with an unsupported
triggered SQL statement.. SQLCODE=-797, SQLSTATE=42987, DRIVER=4.17.29
SQL Code: -797, SQL State: 42987
Could someone help me to identify what's wrong in the SQL statement that's triggered ?
Thank you a lot in advance.
OK I found the answer,
According to http://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000931.html:
The SQL-procedure-statement in a BEFORE trigger cannot: Contain any
INSERT, DELETE, or UPDATE operations, nor invoke any routine defined
with MODIFIES SQL DATA, if it is not a compound SQL (compiled).

Database replication stops if data is changed on the subscriber

Should the SQL database replication stop if i delete one record in a replicated table on the subscriber end?
I remember having a replication running where the delete on subscriber would be overwritten from publisher effectively preventing you from deleting the data.
But in our new configuration it crashed the replication when we deleted one record.
It depends. If you deleted a row at the subscriber that is subsequently updated at the publisher, replication will break when the update is propagated. Why is this? If you look at how the command is replicated, it calls a stored procedure with the PK column(s), a bit mask of what columns changed, and then the list of new values for columns that changed (I'm glossing over some detail, but you can look for yourself in the subscriber database; the procedures are all there and pretty accessible). Because it doesn't re-replicate the whole row again, if it doesn't find the row indicated by the PK, replication assumes (correctly) that the subscriber is no longer in sync with the publisher and stops. As far as I know, replication has never worked in the way you describe.
TL;DR: you should treat the subscriber database(s) as read-only except by the replication process itself.

Replication - Explicit value must be specified for identity column in table

I'm using Merge Replication. The Identity range management is AUTOMATIC
I HAVE A TRIGGER ON COMPANIES TABLE WHICH INSERTS ROWS IN SERIALNUMBERSCHEME TABLE which has documentID as identity column
While synchronizing I'm getting below error
A row insert at 'SERVER\MUMBAI.PROD_SUB' could not be propagated to 'SERVER\NEWYORK.PROD'. This failure can be caused by a constraint violation. Explicit value must be specified for identity column in table 'SerialNumberScheme' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.
Data is inserted properly at subscriber but not replicated at publisher
Any solution/suggesstion?
Sounds like your trigger gets fired when the replication agent applies the updates. Normally the trigger should run only at the publisher (or more precisely, at the site which inserts the original data). Then replication will replicate the effect of the trigger. I think that all you need is to mark the trigger as NOT FOR REPLICATION.
See Controlling Constraints, Identities, and Triggers with NOT FOR REPLICATION.

Adding new article to transactional replication gives error at subscriber

I have an updatable transactional replication set with SQL Server 2008. Everything is working fine. I added a new table to the existing publication thru sp_addarticle followed by sp_addsubscription. After that I ran the snapshot agent. Snapshot has been generated only for newly added table. So the new table was successfully replicated to subscriber. I could even able to replicate a newly inserted record into new table to subscriber. But vice versa is not possible. When I insert a record into new table in the subscriber database, I am getting an error
*Msg 515 'Cannot insert the value NULL into column 'msrepl_tran_version',
table Servername.dbo.Tablename'; column does not allow nulls. INSERT fails.'*.
Please help me to resolve this issue.
Many Thanks in advance. Geeta
Is it reproducible error? Is subscriber configured as Immediate Updating? In case of Immediate Updating subscriber the transaction fails whenever publisher (or network) is unavailable.
Check and change, if it does not have it, your table so that ms_repl_tran_version defaulted to GUID:
ALTER TABLE [dbo].[TableName] ADD
CONSTRAINT [DFLT_GUID_msrepl] DEFAULT (newid()) FOR
[msrepl_tran_version]