SQL Server Triggers: Last Inserted Identity is for Child Record not Parent (Alpha Five V10 and older)

This issue is fixed in Alpha Anywhere.

Description

In Alpha Five Version 10 and prior, an issue exists where the identity returned for the last inserted record is for a child table and not the master table. This issue only applies to SQL Server where an Insert Trigger has been defined. This issue is fixed in Alpha Anywhere.

Discussion

There is a bug in SQL Server when you get the value of the last inserted identity column value under the following situation. Say you have a table (called say, 'MasterTable'). 'MasterTable' has an identity column. 'MasterTable' also has an Insert Trigger which inserts a new record into a table (called say, 'ChildTable'). 'ChildTable' also has an identity column. When you insert a record into 'MasterTable', the following AlphaDAO command can be used to get the value of the last inserted identity column:

<SQL::Connection Object>.CallResult.LastInsertedIdentity

The SQL Server bug is that this command will return the value of the identity value inserted into 'ChildTable' and not 'MasterTable', as you would expect.

Microsoft does not have a fix for this. The problem affects Grid components because retrieving the value of the last inserted identity field is crucial to many aspects of the Grid performance.

The suggested work around is to not use identity columns in tables that are manipulated by triggers. Instead you could use GUIDs for the primary keys of these tables.

This bug has been fixed in Version 11.

This article only applies to Alpha Five Version 10 and prior.