The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Probably Obvious DB Question...


I've run into a situation where cursors appear to be required.  Before I take that route, though, I thought I'd check my assumptions with people more knowledgeable than I - you folks.

What I have is a situation where I need a trigger to monitor changes to a certain table.  When the table changes, I need to do some complicated updates to some other tables (complicated in the sense that I can't do everything that needs to be done with a single statement).

The obvious solution is to put a cursor on the INSERTED table in the trigger, and step through each record, executing the code block on the data pointed at by the cursor.

I've always been warned to stay away from cursors, though, so I've been trying to think of a way to do this without resorting to cursors.  So far, no dice.

I'm using SQL Server 2000.

Anyone have any tricks or tips to share?  Thanks in advance.

P.S.  The reason I have to do these updates is that I'm building a denormalized version of the data optimized for queries, and I want the denormalized version to be updated incrementally in synch with changes to the normalized version.
buster Send private email
Tuesday, December 05, 2006
First, are you sure you need to denormalize? That is, have you found that the existing system is too slow and proven through profiling that the proposed denormalization will solve the problem? I ask because very often people assume that a normalized design will not perform well when in fact it will. Been there, done that.

Assuming that you have done your homework on the database design, use a cursor. It's the right tool for this particular job.
Tuesday, December 05, 2006
Tuesday, December 05, 2006
SQL Server Central just had an article on this topic that might help:

KenW Send private email
Friday, December 08, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz