In SQL server I am trying to do a transaction that will delete customerID 8 from
ID: 3574877 • Letter: I
Question
In SQL server I am trying to do a transaction that will delete customerID 8 from addresses and customers. In the code that I am using I am trying to have it check to see if this has happened prior to commiting to the transaction. If there is no customerID 8 than roll them back. I am getting an error when I run this script and I am looking for help.
Msg 4145, Level 15, State 1, Line 6
An expression of non-boolean type specified in a context where a condition is expected, near 'then'.
BEGIN
DELETE Addresses
WHERE CustomerID = 8;
DELETE Customers
WHERE CustomerID = 8;
IF SQL%FOUND then
COMMIT;
ELSE
ROLLBACK;
END;
Explanation / Answer
The error is in syteax of IF statement. It doesn't requre then
BEGIN
DELETE Addresses
WHERE CustomerID = 8;
DELETE Customers
WHERE CustomerID = 8;
IF SQL%FOUND
COMMIT;
ELSE
ROLLBACK;
END;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.