Re: Create Delete Trigger on Table1 to Update a filed on Table2



SagiPhoenix@AlbionLab (zkvneml@xxxxxxxxx) writes:
ad the condition of the deleted deleted record's identity ID to the
update statement. the ID can be fetched using

select @recKeyID = {identity column name} from deleted

No! No! No!

A trigger fires once per *statement* and there can be more than one
row in deleted/inserted.

And who says that the table has an IDENTITY column? If you have IDENTITY
columns in all your tables, you have a habit that you need to change.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: BULK INSERT into table with identity column?
    ... INSERT into a temp table with an identity column. ... still has to be in the file if you don't use a format file. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Managing an UPDATE executed concurrently?
    ... just use an IDENTITY column? ... Concurrency is taken care of for you, ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.programming)
  • Re: Cannot update identity column PointOfSaleID.
    ... The sp_MSupd_PointOfSales stored procedure checks to see if the bit flag ... set and if so it executes an update statement which includes the identity ... for the identity column, it executes fine and chooses the else path. ...
    (microsoft.public.sqlserver.replication)
  • Re: IDENT_CURRENT
    ... If a table does not have any IDENTITY column ... If your table has a two-column key, it is not likely to have an IDENTITY ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.programming)
  • Re: Synchronous Bulk-Copy into two table
    ... table are there any columns beside the IDENTITY column that are unique ... within a store? ... and if you tell which version of SQL Server you ... Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books ... ...
    (comp.databases.ms-sqlserver)

Loading