开发者

Why are "identity" column values incorrect when I attach a database?

Someone sent me a database (via means of an .mdf and .ldf file) which I attached on a server (with no errors, warnings, etc) and though I don't have proof (since I don't have access to the server the DB cam开发者_高级运维e from), it appears the primary key (identity) values are different from what they were originally. Also, they appear to be "reset" - all primary key values are starting at 1, whereas based on foreign key references it is clear that is incorrect (for example, a table with only 1 row has a primary key value of 1, but a table that references it references a value of 7).

Though I don't really care, I am curious as to why this is happening (if there is an explanation)?

What I really need is to figure out if there is a way to attach the database and retain the proper values?

Edit: As far as I can tell, the foreign key references are set up properly.

Here are some screenshots:

Why are "identity" column values incorrect when I attach a database?

Why are "identity" column values incorrect when I attach a database?

Why are "identity" column values incorrect when I attach a database?


All I can think of since there are FKs is that they had a bad design to start with and then someone realized they neede FKs but there was already bad data they didn't want delete and thus created the FKs WITH NOCHECK

Are all of the orphaned records early ID numbers?


Attaching a database never changes table content. The values you see are all coming from the application that created the database. ``select’’ Isn’t Broken.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜