Android Question SQL Multiple table in a single db

Discussion in 'Android Questions' started by Devan, May 14, 2015.

  1. Devan

    Devan Member Licensed 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.
     
  2. Mahares

    Mahares Well Known Member Licensed User

    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.
     

    Attached Files:

    Devan likes this.
  3. Devan

    Devan Member Licensed User

    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:
     
  4. ivan.tellez

    ivan.tellez Active Member Licensed 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: May 16, 2015
    Devan likes this.
  5. Devan

    Devan Member Licensed 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:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice