Android Question SQL Multiple table in a single db

Devan

Member
Licensed User
Longtime User
Hi There,
Just want to check, whether can we create multiple table using same database in SQL but with different name for each table?
If yes, than how to do it? If not, than what the best way to create.
In my program, user can start new activity or continue previous activity. I want to create new table for every new activity and store it in database to use the table in future.

Pls explain. Thank you for your valuable time.
 

Mahares

Expert
Licensed User
Longtime User
Just want to check, whether can we create multiple table using same database in SQL
Yes, you can create as many tables as you want in the same database. Although it is better if you create all the tables from the main activity and from the start. You can create one table in each activity if you want. Attached is a complete small example that shows you how to create a database, then create one table in the main activity and insert a record, and create the second table in the second activity and insert a record, like you wanted. You can expand and modify it to suit your needs.
 

Attachments

  • SQLiteMultiTables.zip
    12 KB · Views: 211
Upvote 0

Devan

Member
Licensed User
Longtime User
Although it is better if you create all the tables from the main activity and from the start.
Dear Mahares,
Thank you for your valuable time and advice. Also for the sharing of the Multi table file. :)
Just out of curiosity I want to ask, why you mention "better to create all the table from the main activity and from the start". Is it will cause a problem later part to the program?
Have a nice day mate.
Cheers:cool:
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
The main concept of databases is to have the data homogeneous and in a single place. Making multiple tables with the same kind of data is not actually a Database approach, better use files instead.
That's what Devan mean, just create the tables at start, then just use insert, delete update in the rest of the app
 
Last edited:
Upvote 0

Devan

Member
Licensed User
Longtime User
Hi ivan.tellez, thank you for your advice. It gives me more idea. Really appreciate that:). I will try file.
Actually what i need is
1. Create SQL database with create table.
2. When the user start to do new data entry than new table with new data should be created.
3. The old data & old table should still remain in the same database. If needed user must be able to access the previous table & data separately.
Hopefully the above explains my situation.
Have a Great weekend buddy. :cool:
 
Upvote 0
Top