You are here: Re: How do you conditionally fire a trigger (mimic replication) « MsSQL Server « IT news, forums, messages
Re: How do you conditionally fire a trigger (mimic replication)

Posted by David Portas on 10/24/06 06:40

steven@bluemania.co.uk wrote:
> Does anyone know how to do the following. I'm trying to mimic
> replication with triggers.
>
> I have 2 databases, each have these 2 tables.
>
> 1.
> USERS
> ID int
> NAME varchar(20)
>
> 2.
> CHANGES
> TABLE varchar(20)
> TYPE varchar(10)
> col1 varchar(20)
> col2 varchar(20)
>
> On the USERS table I have a for insert trigger. Whenever a new user is
> added the trigger puts an entry into the CHANGES table such as
> ("USERS", "INSERT", "1", "Fred")
>
> I now have an application (vb.net) that monitors the CHANGES table on
> server1. If it finds an entry it determines the table using the TABLE
> column and performs the necessary insert and deletes the entry from
> CHANGES. Now the problem is server2 also has an for insert trigger on
> the USERS table so it puts an entry into CHANGES on server2. As you
> can imagine this goes around in a loop.
>
> What I was hoping for was someway of saying, "I'm inserting from my
> application so don't do the trigger".
>
> Any ideas gratefully appreciated.
>
> Steve.

You could put an INSTEAD OF trigger on a view over the target table.
Updates direct to the table or via another view won't be affected.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация