How to write a delete query after checking?
Description:-
perform a delete SQL query after checking whether the record is present or not.
anyone can use this method to perform other query operations.
Example:-
user_id | user_name | user_email |
1 | Arun | arun123@gmail.com |
2 | Sujan | sujan123@gmail.com |
3 | Rohit | rohit123@gmail.com |
SQL:-
IF EXISTS (
SELECT *
FROM user
WHERE user_email = 'rohit123@gmail.com'
)
BEGIN
DELETE
FROM user
WHERE user_email = 'rohit123@gmail.com'
END
Result:-
user_id | user_name | user_email |
1 | Arun | arun123@gmail.com |
2 | Sujan | sujan123@gmail.com |