Home > database >  Use a TableAdapter. Update appeared in violation of the PRIMARY KEY constraint
Use a TableAdapter. Update appeared in violation of the PRIMARY KEY constraint

Time:05-23

figure 1
2
If the data from figure 1 to figure 2, reoccupy a TableAdapter. The Update would be a violation of the PRIMARY KEY constraints, can't insert duplicate values
I think it is because the database in the change ID=10 to ID=11, ID=11 the line has not changed in ID=12, is there a way to solve this problem?

CodePudding user response:

In database design, once the primary key generation, generally no longer changes, so are not open to the user to change, you consider to change the user interface,

CodePudding user response:

A primary key is not can't change, can change, now is because the value is not a duplicate, so an error

CodePudding user response:

1. Do not recommend using constraints in the database, can lead to abnormal data lock, has the above situation, the back-end logic can be used to control the key constraints,
2. The solution - the weak constraint, the way don't constraint, the two try to set up the primary key of the foreign key, do not use strong constraint method to process the data, test time is not convenient, go up, the basic will not adopt the way of directly modify data in the database to handle,
Supplement: delete constraints, again through the program to write data, won't appear this problem,
If you must, it is not recommended to modify data in the database directly,

CodePudding user response:

reference Main_csdn_String reply: 3/f
1. Do not recommend using constraints in the database, can lead to abnormal data lock, has the above situation, the backend logic can be used to control the key constraints,
2. The solution - the weak constraint, the way don't constraint, the two try to set up the primary key of the foreign key, do not use strong constraint method to process the data, test time is not convenient, go up, the basic will not adopt the way of directly modify data in the database to handle,
Supplement: delete constraints, again through the program to write data, won't appear this problem,
If you must, is not recommended to modify data in the database directly,



I also have thought of before, in the database to set up a list of to do the ID column, do not restrain, primary key, the back-end load but hide the primary key columns, the back-end to determine whether the new ID column inside have duplicate values, if there is no UPDATE,
Mainly is to want to save trouble, look have other way to solve the , have to add the back-end code in our province
  • Related