0

Is it possible to example use:

String sql = "DELETE field FROM table1, table2 WHERE field='x', field='y'";

To delete multiple fields from multiple tables? I ask because I am using creating a clean up method that will go through and delete all references to an object in all of my database tables when I delete that object and it seems easier to add everything into one sql statement as opposed to building a separate sql for each table and then executing each one individually. If one statement isn't possible is there another solutions? Such as building an sql array perhaps and then executing all with one command?

2
  • Don't know which DBMS that is on Android, but DELETE field FROM is an invalid (standard) SQL statement. DELETE does not work on column level, it works on row level. Commented Jul 30, 2011 at 23:03
  • @a_horse_with_no_name: The standard is, AFAIK, SQLite for both Android and iOS. Commented Jul 30, 2011 at 23:44

3 Answers 3

0

You can't do that. You need to do multiple delete statements, one per table.

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

1 Comment

I kinda figured that much, but just thought i'd check. Thanks.
0

Many databases allow for several statements to be in one string separated by ; and then executed in one command.

e.g.

String sql = 
         "DELETE FROM table1 WHERE field='x' and field='y'; 
          DELETE FROM table2 WHERE field='x' and field='y';";

 Command.Commandtext = sql;
 Command.Execute();

However I do not have specific knowledge about Android so if I'm wrong let me know.

Comments

0

Are you trying to delete the field or the entire row? If row then yes you can do the delete in all the tables, if they have Foreign Keys.

Take a look at this post MySQL delete row from multiple tables

That should give you the clue and good luck...

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.