0

I am trying to update the employee data in sqlite. Employee ssn number of two data is mistakenly swapped and now when i try to swap the data again with the code below:

UPDATE employee SET SSN=’666884444’  WHERE SSN = ‘123456789’; 
UPDATE employee SET SSN=’123456789’ WHERE SSN = ‘666884444’;  

it shows me the following error:

[16:51:19] Error while executing SQL query on database 'Company': 
FOREIGN KEY constraint failed

Can someone please guide me with the query?

2
  • One of those numbers probably doesn't exist in the table that employee.ssn is related too. You can temporarily turn off foreign key checks with a pragma and turn them back on after doing this. Commented Aug 22, 2018 at 8:18
  • Also, I don't think that attempt to swap will actually work. Commented Aug 22, 2018 at 8:18

1 Answer 1

0

https://www.sqlite.org/foreignkeys.html

  1. Change the FK constraint to DEFERRED. Syntax is DEFERRABLE INITIALLY DEFERRED.
  2. Do your updates inside a BEGIN/COMMIT transaction block.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.