By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

Finding identity column value from a table

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SELECT @@IDENTITY Can retrieve the Identity of the last insertion.

....Ashok

"Devesh Aggarwal" <so*******@unieme.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
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

Jul 21 '05 #2

P: n/a
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

"G.Ashok" <gw******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
SELECT @@IDENTITY Can retrieve the Identity of the last insertion.

...Ashok

"Devesh Aggarwal" <so*******@unieme.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
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


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.