Tag: The person string set succeeds Deb causes the code lang to be set
The primary key must be unique in the same table, and if the primary key specified at the time of the data update is duplicated with the data already in the table, the exception that violates the PRIMARY KEY constraint is caused. The Fnumber field in the T_debt table is the primary key if we execute the following sql:
UPDATE T_Debt set FNumber = "2" WHERE FPerson="Tom"
Since a record with a fnumber field of 2 already exists in the table, an error message similar to the following is reported when running this sql:
Violates the primary KEY constraint "PKt_debt1920bf5c". cannot be in the object "dbo." Insert duplicate key in T_DEBT.
And if we set a distinct value for fnumber, it will be inserted successfully, execute the following sql:
UPDATE T_Debt set FNumber = "8" WHERE FPerson="Tom"
This sentence of SQL can be successfully executed correctly. Perform a SELECT * from t_debt to view the data in the table:
You can see that the data has been updated correctly in the table.
Impact of primary key on data update