SQL管理中的主键值问题 [英] Primary key value problem in SQL managment
问题描述
我在数据库的发送请求表中插入了一些数据。我使用了断点,它显示主键的值为1但是当我在SQL管理工作室中检查它时,主键值每次大于1000。请帮我解决这个问题以及解决方法。
我删除了该表中的所有记录。没有数据,这意味着当我插入新数据时,它应该在id 1上,但它在id 1003或1004上。
我尝试过:
我在互联网上搜索过并且我使用过ressed表身份,但它不能在asp .net mvc中工作。
I am inserting some data in send request table of my database. I have used break point and it shows that primary key has value of 1 but when i m checking it in SQL management studio there primary key value is greater than 1000 each time. please help me what is this problem and how to solve it.
I have deleted the all records from that table. there is no data it means when i m inserting the new data it should be on id 1 but its on id 1003 or 1004 .
What I have tried:
I have searched on the internet and i have used ressed table identity but its not working in asp .net mvc.
推荐答案
正如 NotPolitcallyCorrect [ ^ ]您可能使用自动递增的身份。
首先,由于这种密钥定义仅作为单行的唯一标识符,因此值无关紧要。 1000和1一样好,因为它只标识一行。
你的编号可能总是有差距。例如,如果
- 你在表格中添加三行:1,2和3
- 你删除第2行
- 你现在有行1和3
如果您仍想重置身份,请查看使用 DBCC CHECKIDENT(Transact-SQL) [ ^ ]
As pointed out by NotPolitcallyCorrect[^] you probably use an automatically incrementing identity.
First of all since this kind of key definition serves only as a unique identifier for a single row, it should not matter what the value is. 1000 is just as fine as 1, since it just identifies a row.
You will probably always have gaps in the numbering. For example if
- you add three rows in the table: 1, 2, and 3
- you delete row 2
- you now have rows 1 and 3
If you still want to reset the identity, have a look at reseeding the value with DBCC CHECKIDENT (Transact-SQL)[^]
这篇关于SQL管理中的主键值问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!