buco
buco

Reputation: 41

How should I design my tables in relation database?

I have a source code that comes in this type of XML which I have to parse and save to database.

<stock date="23.2.2016">
    <sth mark="aaa">111</sth>
    <sth mark="bbb">222</sth>
    <sth mark="ccc">333</sth>
</stock>
<stock date="24.2.2016">
    <sth mark="aaa">444</sth>
    <sth mark="bbb">555</sth>
    <sth mark="ccc">666</sth>
</stock>   

I tried to make two tables with one for stock and one for sth in XML and to relate to them. When I tried to populate them I didn't know how to. The problem is I think that my design is bad. If I try to do it with only two tables the second one would become much too big and creating a new table for each stock entry just seems wrong. Any advice or sample code on how to solve this would be greatly appreciated.

Upvotes: 0

Views: 42

Answers (1)

bitrecycling
bitrecycling

Reputation: 55

Was there any specific reason for why you created two tables in the first place? If not, just create one table containing all data plus date (timestamp):

aaa | bbb | ccc | date
111 | 222 | 333 | 23.2.2016
...

This should suffice and still conforms to normalization principles, since all data is unique to the entry and there's no unnecessary duplication.

Upvotes: 1

Related Questions