Reputation: 6500
I have a simple database named customer with a single table data.I want to check if a customer name exits in the database,if then i want to delete it.I'm using MYSQL Connector for this.
EDIT:
I want to make sure the value is present before deleting to display
a simple user message.
Upvotes: 0
Views: 1282
Reputation: 22895
Why not just deleting it?
DELETE FROM customers WHERE customer_name = 'John Smith';
If it exists, it will be deleted. Otherwise no rows will be affected.
EDIT:
If you need a more complicated process, then I recommend (in order):
ON DELETE FOR EACH ROW
trigger, that will auto update flags upon deletion; START TRANSACTION;
UPDATE flag_table SET is_deleted = 1 WHERE customer_name = 'John Smith';
DELETE FROM customers WHERE customer_name = 'John Smith';
COMMIT;
It would be easier to answer if you could provide more details on your design.
Upvotes: 6
Reputation: 71
you can use a trigger for this purpose, mysql will delete if any repetation is found on insertion.
Upvotes: 0