Three paradigms of MySQL database design

Design paradigm overview

  • The design paradigm is the basis for designing the table, and the table designed according to these three paradigms will not have data redundancy
  • The database design follows the three paradigms as much as possible, but in actual development, it is mainly to meet customer needs, and sometimes redundancy is exchanged for execution speed

1. First Normal Form

  • Duplicate records cannot appear in the database table, each field is atomic and cannot be divided
  • In the first normal form, each table must have a primary key, which is usually represented by a numeric value or a fixed-length string, and the columns cannot be subdivided and should be determined according to specific circumstances
  • Has a primary key, records are not repeated, and fields are atomic

Second, the second normal form

  • The second paradigm is based on the first paradigm. In addition, all non-primary key fields are completely dependent on the primary key and cannot be partially dependent.
  • Fully dependent, no partial dependence
  • Many-to-many design: the relational table has two foreign keys

Third, the third normal form

  • Based on the second paradigm, all non-primary key fields directly depend on the primary key and cannot produce transitive dependencies
  • No transitive dependency
  • One-to-many design: two tables, multiple tables plus foreign keys

Four, design plan

1. One to One

1. Primary key sharing
2. Foreign key unique

2. One to many

  • Two tables, more tables plus foreign keys

3. Many to Many

  • The relational table has two foreign keys

Guess you like

Origin blog.csdn.net/LvJzzZ/article/details/109014024