Normalization in MYSQL

前端 未结 5 2319
囚心锁ツ
囚心锁ツ 2020-11-22 12:58

What is normalization in MySQL and in which case and how we need to use it?

5条回答
  •  生来不讨喜
    2020-11-22 13:37

    While creating a database schema for your application, you need to make sure that you avoid any information being stored in more than one column across different tables.

    As every table in your DB, identifies a significant entity in your application, a unique identifier is a must-have columns for them.

    Now, while deciding the storage schema, various kinds of relationships are being identified between these entities (tables), viz-a-viz, one-to-one, one-to-many, many-to-many.

    1. For a one-to-one relationship (eg. A Student has a unique rank in the class), same table could be used to store columns (from both tables).
    2. For a one-to-many relationship (eg. A semester can have multiple courses), a foreign key is being created in a parent table.
    3. For a many-to-many relationship (eg. A Prof. attends to many students and vice-versa), a third table needs to be created (with primary key from both tables as a composite key), and related data of the both tables will be stored.

    Once you attend to all these scenarios, your db-schema will be normalized to 4NF.

提交回复
热议问题