0

When I run:

DELETE FROM `examplecompname_empdata` WHERE `Emp_ID` = '1'

I get the following error: Unknown column 'examplecompname_empdata.Emp_ID' in 'where clause'.

I have 2 tables examplecompname_empdata and triggertable.
I've already created a delete trigger, when i delete a data in examplecompname_empdata it must delete the same id in triggertable. But after i click the delete data in my dashboard it says:

Unknown column 'examplecompname_empdata.Emp_ID' in 'where clause'
DELETE FROM `examplecompname_empdata` WHERE `Emp_ID` = '1'

I create the trigger on examplecompname_empdata with this code:

BEGIN
DELETE FROM triggertable

WHERE triggertable.id = examplecompname_empdata.Emp_ID;

END

Why am I getting this error?

3
  • It's been a while since I've last used SQL, but table.Emp_ID is a column in the table. Are you sure you have this column? PHPMyAdmin seems to be telling you that you don't have it, maybe there's a typo Commented Jan 16, 2018 at 4:40
  • Where is the id you want to delete in the second delete statement? Provide a complete code example. Commented Jan 16, 2018 at 4:49
  • sorry. my table examplecompname_empdata id is "Emp_ID" and triggertable id is "id" link i used that link for basis Commented Jan 16, 2018 at 5:30

1 Answer 1

0

I think you the AFTER DELETE statement in trigger definition.

// begining codes.....FOR EACH ROW
BEGIN
   DELETE FROM triggertable

   WHERE triggertable.id = OLD.Emp_ID; // not the table.id 

END

See MYSQL DELETE TRIGGER

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.