Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 @@identity and insert trigger

Author  Topic 

rj_khatri
Starting Member

13 Posts

Posted - 2002-07-20 : 02:38:16
Dear friends,
Hi there!

I am very much puzzled with the following problem:
I have 2 master & detail tables. In master table there is one identity column,
On master table there is one insert trigger.
On entry in master table , trigger also insert the value in detail table also that entry is made in another table too.
My actual problem is @@identity that actually returns null.

It was previously working very fine(2 months before) but now it is behaving strangely.
I have not made any change in table structure. After looking thru every
angle i got the point that @@identity is not working..

If anyone can help me please respond soon.
Thanx in advance.

Rajesh Khatri

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-07-20 : 06:41:44
If you are working with SQL7, the @@IDENTITY function returns the last value. In your case, it returns the @@IDENTITY for the detail table, not the master table. In SQL2000, there are multiple forms of @@IDENTITY that allow you to get the master table identity and not the trigger-based detail table.

If you're using SQL7, you may need to rewrite without a trigger to get the correct @@IDENTITY.

Go to Top of Page

SQuirreL
Starting Member

9 Posts

Posted - 2002-07-20 : 13:30:31
quote:

In SQL2000, there are multiple forms of @@IDENTITY that allow you to get the master table identity and not the trigger-based detail table.



An article here on SQLTeam that explains the differences between the types of @@IDENTITY is available at [url]http://www.sqlteam.com/item.asp?ItemID=319[/url]

--edited for spelling errors resulting from typing without thinking

Edited by - SQuirreL on 07/20/2002 13:32:12
Go to Top of Page
   

- Advertisement -