Android - How do I create and combine two tables within a list of SQLite tables on Android?

1

I'm creating an application to monitor the aquarium settings using the following scheme:

The user can monitor as many tanks as he wants, but every time he adds a new aquarium, these two tables should be created and always linked.

And the water parameters need to be maintained over time as I'll use them on a chart. Showing changes over time. For example, a chart showing the amount of salt over the course of a week.

That's where my doubt comes in, because I'm starting to program in a little while.

  • How can I create and merge these two tables, every time the user adds a new aquarium?
  • And how would I not mix with other tables, if the user had added 5 aquariums in the app?
  • I've been researching and seen what foreign key might be useful in my case, but I do not know if that would help me or how to proceed.

    Note: Just a clarification. I do not need the be-a-bá, I have a basic knowledge on Android. I know how to handle a db, do CRUD operations, Cursor, ContentProvider, etc. But I'm lost in this case. I do not want to look lazy. Just no sense of which way to go or what tools to use.

        
    asked by anonymous 03.05.2018 / 11:05

    1 answer

    0

    You need to add a new column in the parameters table, this column will be a foreign key that will refer to the primary key of the aquarium (aquarioId) table:

    CREATE TABLE parametros(
        //...
        aquerioId INT NOT NULL,
        FOREIGN KEY(aquerioId) REFERENCES aquerio(aquerioId)
    );
    

    Whenever you add a new row in the parameters table, you must add the aquarium id that that row refers to

    Note that the foreign key must be the same data type and size as the primary key it refers to

        
    03.05.2018 / 12:49