-1

After taking the backup of database, when i tried to restore it, the seed of identity is reset to 0. So when i try to insert any new values, the id (primary key) is started 1.

Now the issue is, i have relational data tables. let say from table x after some operation the data is moved to table y. But as the seed is set to 0, the values of id of table x and table y clashes. and that gives me error.

Is there a any way while taking the backup, we can save the value of identity also.

P.S. :

  1. size of database is huge and manual alteration is next to impossible.
  2. seed of identity is reset to 0 only when the table is empty.

Edit :

Sorry for a bit confusion, by backup, i mean export (my bad). as the empty tables's seed is set to default, primary key in my tables are clashing, so with export of database, i need to store the values of identity of every table also.

Is there any way i can do that ?

Mr.Bhanushali
  • 126
  • 12

1 Answers1

2

The identity seed is not reset or modified when using

  • BACKUP DATABASE
  • RESTORE DATABASE

You must be exporting and importing data, which is not backup and restore.
I say again

  • BACKUP DATABASE is the only way to backup the database
  • RESTORE DATABASE is the only way to restore the database,

If you want to keep export/import method, then simply use DBCC CHECKIDENT to reset the seed.

Also read this to see why the seed is set to zero:
SQL server identity column values start at 0 instead of 1

gbn
  • 422,506
  • 82
  • 585
  • 676