why do we divide a mysql table into many smaller tables?

后端 未结 2 1721
生来不讨喜
生来不讨喜 2021-01-31 06:20

it seems that it is a common practice to divide the data of one table into many databases, many tables to improve performance, i can understand the many datab

2条回答
  •  花落未央
    2021-01-31 06:59

    Data is split into smaller tables to 'normalize it'. This is a very interesting concept. You may read more on it here.

    http://en.wikipedia.org/wiki/User:Jaseemabid/Books/Database_normalisation

    A quick example.

    Assume a small phonebook app, allowing people to have multiple numbers.

    One way of design would be like this

    • Name |Number
    • A | 123
    • A | 95467
    • B | 179

    The problem with this is that when we have to update the name of A and if we dont update all , it will cause confusion. So we can split this into two tables like this.

    • Unique ID | name
    • 1 | A
    • 2 | B

    • Unique ID | number

    • 1 | 123
    • 1 | 95467
    • 2 | 179

    This will solve the issue. constrains can be handled in an awesome manner using "foreign keys" , please read abt it to understand the whole concept properly.

    Hope you get it :)

提交回复
热议问题