I ran into a problem with an Android application, where I needed to create multiple database tables. There’s a small catch to remember that may save you a headache – but it’s just a matter of coding the database access layer right. Your database access layer may define SQL code for database tables like this: […]

This article was posted by Independent Software, a website and database application development company based in Maputo, Mozambique. Our website offers regular write-ups on technical and design issues, ranging from details at code level to 3D Studio Max rendering. Read more about Independent Software's philosophy, or get in touch with Independent Software.

I ran into a problem with an Android application, where I needed to create multiple database tables. There’s a small catch to remember that may save you a headache – but it’s just a matter of coding the database access layer right.

Your database access layer may define SQL code for database tables like this:

The SQL is then executed so:

However, there’s a danger here. Android does not actually allow you to execute more than one SQL statement with a single execution. It is necessary to split up the table creation SQL into two separate statements, which are executed one by one:

The statements are then executed like this:

If you don’t do this, the second table will never get created, and no warning is issued about it.

Did this article help you out? Please help us find more time to write useful guides & articles like this by donating a buck or two. It'll keep us coffee-fueled. Thanks!

Comments

2 2 Responses to “Android: Cannot create multiple database tables”
  1. prashant says:

    i used the second method, separate execution for every create string. for each of them, none f the tables are created ever. error says “No such table found”. if you can, please reply.. i used he first method too, error turns to be the same…

  2. Hi, thank you very much!! It helps me a lot. What makes it very confusing is it doesn’t raise any exception.

Leave a Reply

Your email address will not be published. Required fields are marked *