Re: Modifying Primary Key Values

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 10/21/04


Date: Thu, 21 Oct 2004 11:49:12 +0200

On Thu, 21 Oct 2004 10:30:25 +0300, ggeshev wrote:

>Hello!
>
>Let's suppose I have a table MyTable (A INT PRIMARY KEY, B VARCHAR(20)).
>
>
>
>I send an UPDATE script to sql server.
>
>In this script I modify the A column /the primary key/.
>
>In an AFTER UPDATE TRIGGER I would like by analyzing "inserted" and
> "deleted" virtual tables to understand which row from "inserted"
>corresponds to which row in "deleted".
>
>You understand that I cannot rely for that purpose on the A column /the
>primary key/ because values in it are changed.
>
>How can I make the true correspondence between "new" and "old" rows?
>
>
>
>Thank you!
>

Hi ggeshev,

The only reliable way to do this is to use a combination of other columns
in the same table; this combination should also be unique and the columns
should not be updated as well in the same statement.

If you have no other unique column (or unique combination of columns) or
if that column(s) is updated as well, you're out of luck. You could try to
get a best match based on comparison of all other columns in the table,
but you can never be completely sure that you are correct.

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: Modifying Primary Key Values
    ... Do you have an alternate key you can use for this purpose? ... > I send an UPDATE script to sql server. ... > How can I make the true correspondence between "new" and "old" rows? ...
    (microsoft.public.sqlserver.programming)
  • Re: Connection to a MS SQL Server Table (newbie)
    ... > machines with IIS and MS SQL Server. ... The latter seems to defeat the purpose of a password. ... > What I am guessing at this point is that a SQL server account needs to be ...
    (microsoft.public.inetserver.asp.db)
  • Re: SQL SERVER
    ... SQL Server is manly used to store data in a relational way (but it's still ... > purpose. ...
    (microsoft.public.sqlserver.msde)
  • Re: More than one index on a table
    ... I know we hate this kind of answer, ... I support the Professional Association of SQL Server and it's community of SQL Server professionals. ... > I have a table with 100 million rows and have a unique> clustered index on name, date which serves its purpose. ...
    (microsoft.public.sqlserver.server)