Finding identity column value from a table

D

Devesh Aggarwal

Hi,

I have a backup and restore module in my project. The backup uses a typed
dataset object (XSD) to get the data from database and creates a xml file as
the backup file (using the WriteXml method of dataset). When doing the
restore i have to overwrite the data from xml back to database.

these are the steps that i follow.

1. get the data from database.
2. delete the data of step 1.
3. load the xml data.
4. transfer the xml data back on database.

The problem is the master tables have primary key as identity. How do i get
the next identity for a table?
database has over 100 tables with the relation ship created.
all the above four action will happen in transaction.
XSD is created from server explorer in Visual studio.NET.
Database used is SQL 7.

Regards.
Devesh Aggarwal / Hafeez
 
D

Devesh Aggarwal

Hi,

Thanks for the reply, but that doesn't solve the issue.

The @@identity returns the last identity value for the last insert in the
databse irrespective of any particular table.

But in our case we want the identity value before we insert the record in
the table. We want the last identity value only for a particular table. We
can do that in SQL 2000 using iden_current (tablename). Is there a way to do
the same in SQL 7.

Right now i am using a workaround which i fell is not right as there are
more than 100 tables & the time taken is too high. I insert a dummy record
get the identity using @@identity, delete the dummy record & then insert the
new record from the XML file for that table. I repeat the same for all 108
odd tables.

Any suggestions would be highly appreciated as the performance of the
application has gone down dratically because of this.

Regards,
Devesh Aggarwal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top