I have a table
like below:
+--------+--------+
| TestNo | Value |
+--------+--------+
| 1 | Test1 |
| 2 | Test2 |
| 3 | Test3 |
| 6 | Test6 |
| 7 | Test7 |
+--------+--------+
in which TestNo
is the Primary Key
and have the following values.
Notice that the 4, 5
TestNo
values are missing here. What I need is to insert the new value to start with TestNo 4
.
So I did this:
dbcc checkident('tbl', reseed, 3)
It worked and after inserting 2 records:
+--------+-------+
| TestNo | Value |
+--------+-------+
| 1 | Test1 |
| 2 | Test2 |
| 3 | Test3 |
| 4 | Test4 |
| 5 | Test5 |
| 6 | Test6 |
| 7 | Test7 |
+--------+-------+
but after inserting the 3rd record I get following error:
Violation of PRIMARY KEY constraint 'PK__QCUnitTe__554AD375D32C4684'. Cannot insert duplicate key in object 'dbo.QCUnitTest'. The duplicate key value is (6). The statement has been terminated.
So is there any way to overpass the value if it exists? Like in my case it should overpass it to 8
.