View Single Post

   
  #1 (permalink)  
Old 02-29-2008, 06:50 AM
nils.hagner@3dio.co.uk
 
Posts: n/a
Default Newbie trigger question

I haven't used triggers before, but I suppose they would solve the
problem I am having. If anyone can give me some advice on this, then I
would be very grateful.

The problem is that I need to "sync" two tables used by two different
applications. Assume, for example, that the tables are defined as:
table1(A, B, C, D, E) with A being PK, and
table2(A, B, D) again with col A as PK.

When a record is inserted or updated in table2, the following should
happen:

(1) if there already is a row in table1 with the same key (i.e.
table1.A = table2.A), then I want to update table1 to set
table1.B = table2.B and table1.D = table2.D

(2) if there is no row in table1 with that key, then a row
should be inserted with values (A, B, null, D, null)

The DB is SQL Server 7.0. All help is highly appreciated.

Sincerely,

Nils Hagner
nils.hagner@3dio.co.uk

Reply With Quote