8

I need a procedure for delete multiple rows in multiple tables by passing array set of values in parameters

Consider 3 tables:

student_master(id,student_name);
subject_master(id,subject_name);
marks(id,student_id,student_id,subject_id,marks)

here in parameter for e.g student id will be: a['1','3','7','15']

What is the procedure for this criteria?

4
  • 1
    From which tables do you want to delete the rows? To which IDs do those values relate to? And why are you passing numbers as strings? Commented Mar 27, 2017 at 7:22
  • by passing student id i want to delete all the data related to that student id. from other tables(subject and marks) i need just pass a id's in array. Commented Mar 27, 2017 at 7:30
  • Do you use foreign keys? If so, how did you define them? ON DELETE CASCADE can help you a lot in your case. Commented Mar 27, 2017 at 8:01
  • @pozs & a_horse thanks for your solution Commented Mar 27, 2017 at 10:07

1 Answer 1

20

If your student_id s are integer or bigint then use without quote:

delete from marks
where student_id = ANY(Array [1,3,7,15])
returning student_id
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.