Search code examples
sql-server-2000replicationsql-server-2012

How do replication agents enable NOT FOR REPLICATION mode?


How do triggers/identity columns/check contrains marked as NOT FOR REPLICATION get bypassed when the user connecting is a "replication agent"?


If i am an SQL Server replication agent, and i connect to a server to perform replication, how do i indicate to SQL Server that i am a replication agent, so that not for replication rules are enabled on all tables?

Why am i asking?

Because (choose one):

  • to expand the limits of human knowledge and understanding
  • because i'm writing my own replication system

Solution

  • I believe this is done internally using sessionproperty():

    declare @is_replicationagent bit
    select @is_replicationagent = convert(bit, sessionproperty('replication_agent'))