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)
 Problem in inserting record in Detail table using @@identity

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-11-24 : 07:51:21
Abdul Rehman writes "hi
i have two tables table1(Master Table),table2(Detail Table)
I have taken all the Primary keys in all my Database as 'Identity' to boost up the speed.

now when i Execute the Statment "insert into...;select @@identity.", it return the correct answer (the max number from Table1), after that i have a Loop in which i have inserted records in Table2, which have reference from Table1

i d't know whts happen to @@identity it insert the identity of Table2 instead of Table1
pl help me...
waitting for your reply
Regards
Abdul Rehman"

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2003-11-24 : 08:42:55
Hi,
U can use ident_current(table_name) function instead of @@identity which returns the next identity value of the table specified, whereas @@identity gives the next identity value of the last identity table which in your case is Table2.
Go to Top of Page
   

- Advertisement -