Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 20th, 2008, 08:04 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help on Trigger

Hi All,

I have a problem with using Triggers. I have 2 tables which have the same columns but are situated on 2 different databases. I need to write triggers for Insert, Update on both databases, so that if I Insert a record in the Table in Database 1 it should be reflected in the Table in Database 2.Same vice-versa. There are Unique Keys on both sides on which Insert,update Triggers would run.

Kindy help me in how to go about it.

I am having problems in while Inserting as Inserting in Database Table is firig the Triggers for the table in the Other Database and resulting in error.
Reply With Quote
  #2 (permalink)  
Old August 20th, 2008, 08:43 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I can think of three options that may help, it depends somewhat on what is meant by different databases, are they on the same server or different ones?
 
  • Look at setting nested triggers to 0 at some stage
  • Use replication instead of triggers
  • Examine the CONTEXT_INFO before executing trigger code, you can set the CONTEXT_INFO yourself to disable the second trigger


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old August 20th, 2008, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

As another really hacky way to do this (not recommended, but if for some reason Joe's suggestions can't work in your situation), you *could* simply add a dummy field to each table that your normal INSERT and UPDATE operations ignore (e.g., use a DEFAULT of NULL or some such). But in the trigger code, you purposely use a non-default value when you replicate the records into the other DB. And then the trigger code looks for a non-default value and does nothing when such is found.

Ugh. I can't believe I'm suggesting this. Please try Joe's suggestions first! (Especially see if you can't just use replication.)
Reply With Quote
  #4 (permalink)  
Old August 21st, 2008, 02:07 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe & Old Pedant,

Thanks for your suggestions. Since the databases are on the same server I would first try setting nested triggers with Update and try setting them to 0. I am not too confident on replication so I would rather try this first.


Thanks again,
Arny
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger Help monika.vasvani SQL Language 2 March 1st, 2007 06:59 AM
Trigger arshad mahmood C++ Programming 4 June 24th, 2004 07:10 AM
Trigger ! minhtri Pro VB Databases 2 June 23rd, 2004 02:27 AM
Trigger arshad mahmood SQL Language 2 May 12th, 2004 05:16 AM
Using instead of trigger dmr999 SQL Server 2000 1 November 29th, 2003 02:35 PM



All times are GMT -4. The time now is 04:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.