Re: Trigger for updated rows when PK changed
From: John (jsparrowNOSPAM_at_ecclesdeletethiscollege.ac.uk)
Date: 07/18/04
- Next message: Anith Sen: "Re: Primary Key Dilemma"
- Previous message: Dan Guzman: "Re: WRITETEXT - I'm utterly confused By BOL"
- In reply to: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Next in thread: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Reply: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 18 Jul 2004 19:19:36 +0100
I see what you mean!
Maybe updating a pk field should cause delete & insert triggers to be
called, rather than the update trigger?!?
I guess in pure relational theory updating a pk is meaningless - it's always
a delete + insert?
Calling AFTER UPDATE suggests the db knows a physical record was simply
modified (back in base reality where unordered sets don't actually exist!
LOL), even though it's not possible to tell which was altered (without
something like a seperate identify field).
Presumably a row-level trigger in something like Oracle would reflect this
too? 'pk used to be 7, now changed to 17'.
John
"Steve Kass" <skass@drew.edu> wrote in message
news:eKdD0DObEHA.384@TK2MSFTNGP10.phx.gbl...
> John,
>
> The before and after values of what? Unless you have set of columns
> other than the primary key to uniquely the rows of your table, and those
> columns are not updated, you can't make sense of the question. The
> table has some rows before the update, and the table has some rows after
> the update. Who's to say whether they are even the "same rows,"
> whatever that would mean, and which post-update row is the same as which
> pre-update row, if the only way to tell one row from another is by
> reading the primary key value, since the update may have altered any or
> all of those values?
>
> The only way to be able to talk about "this particular row" is if
> "this particular row" means something specific - it has to mean "the row
> with this particular key value". If you need to make sense out of the
> statement "the primary key value of this particular row was changed from
> 101 to 204", there has to be some way to know which row is "this
> particular row" other than by inspecting the value of the primary key.
>
> Suppose that before an update the primary key values in a one-column
> table are 1, 2, and 3. After the update, there are still rows with
> primary key values 2, and 1, but there is no row with key 3, and there
> is a row with key 0. Was the 3 changed to a 0 - and if so, were the 1
> and 2 swapped or not? Or was each number decreased by 1? The query
> processor can have done any of these things. In fact, maybe "the 0" (if
> it meant something) came from another table where a 0 had been deleted
> and was available for reuse, and maybe "the 3" got used by another
> program that needed one.
>
> Steve Kass
> Drew University
>
>
> John wrote:
>
> >Does anyone know of a way to discover before and after values in a AFTER
> >UPDATE trigger when the primary key has changed?? I need this to work
with
> >multi-rows too!
> >
> >I'm familiar with the 'inserted i inner join deleted d on i.pk = d.pk'
> >technique for seeing 'before' and 'after' values, but of course this
doesn't
> >work when the pk is changed.
> >
> >Help!
> >
> >I guess the only solution is to ensure pk field(s) are never altered?
> >
> >John
> >
> >
> >
> >
- Next message: Anith Sen: "Re: Primary Key Dilemma"
- Previous message: Dan Guzman: "Re: WRITETEXT - I'm utterly confused By BOL"
- In reply to: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Next in thread: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Reply: Steve Kass: "Re: Trigger for updated rows when PK changed"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|