0

This is what my DB looks like:

enter image description here

I am trying to delete all the records from both these tables where ID = 8.
This is what I've tried:

DELETE from users1,pontaj WHERE users1.id, pontaj.id  IN(8)

1 Answer 1

1

If you had defined potaj table with pontaj.id as

CREATE TABLE pontaj (
  id int, foreign key(id) references users1(id)
         on delete cascade on update cascade
)

then just executing

DELETE from users1 WHERE users1.id IN(8)

would have deleted records from both parent and child tables.

Sign up to request clarification or add additional context in comments.

8 Comments

Sorry for the stupid question, but If I run this as a SQL command, I get an error. Should I delete pontaj table, then run the query ?
@ExtremeSwat: No. If users1.id has an index defined on it, this solution should work. Otherwise define a key(id) in users1 tables. But your images map shows that the referred field is a primary key and hence it should have worked without any issue.
No effect whatsoever over the other 2 tables.The command just deletes the id from the 1'st table hmm...
@ExtremeSwat: Perhaps the child fields are defined with on delete set null.
@ExtremeSwat: Run show create table pontaj; and show create table salariu; and see how the child columns are defined as.
|

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.