Auto-increment Columns cannot insert duplicate primary keys. Solution

Source: Internet
Author: User

A very fast problem occurs. In an int auto-increment table, the primary key field is not involved when information is inserted. the following error occurs: violation of primary key constraint 'pk _****'. cannot insert duplicate key in object 'dbo. tablename '. duplicate keys cannot be inserted in the table!

The same error is reported when the statement is directly executed in the query analyzer.

Solution:

1. Cancel the primary key and then set the primary key,ProgramRun as usual

2. Execute the following SQL statement, copy the result, and run

Select 'dbcc checkident ('+ table_name +') 'from information_schema.tables where table_type = 'base table'
Cause: the seed value is not synchronized with the actual value in the Table. the DBCC checkident statement is used to check if the current ID value of the table is smaller than the maximum id value stored in the column, use the maximum value in the ID column
Line reset ~!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.