467,858 Members | 1,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

Finding identity column value from a table

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
  • viewed: 1478
Share:
2 Replies
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
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.

Similar topics

4 posts views Thread by Aaron W. West | last post: by
6 posts views Thread by Who.Really.Really.Cares | last post: by
2 posts views Thread by Devesh Aggarwal | last post: by
4 posts views Thread by shorti | last post: by
15 posts views Thread by gunnar.sigurjonsson | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.