I am newbie in this field.

I need to design database. Abstract: there is a counter in every apartment, which is monitoring utility bills. Payments for gas and electricity. There are many houses in a city, but there is only one counter in one apartment. I need to create proper database.

I suppose that it looks like 'one-to-many' connection, so:

  • First table: id_counter (primary key), address

  • Second table: id_counter, cubicmetre_amounts

  • Third table: id_counter, consumed_Vt

Do I understand it correct, is it really 'one-to-many' and if so, what should be the primary key in a second and third tables?

Thanks in advance!


You would need a table for the individual bills, too, would you not?

  • Table 1: individual bills with external key to table 2
  • Table 2: Apartments (are "houses" the same as apartments?) with external key to Table 3
  • Table 3: City information

Your keys would be whatever unique identifier you have set up for each item.

If houses can hold multiple apartments, then you will need to have another table inbetween Table 2 and Table 3.

and yes, this really are one-to-many relationships between all mentioned tables. You cannot have a single bill that can go to multiple apartments, and an apartment cannot be in multiple cities (or houses).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.