The content this article brings to you is about the four paradigms of databases. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. 1NF (First Normal Form)
The first normal form means that each column in the database table is indivisible basic data Items cannot have multiple values in the same column, that is, an attribute in the entity cannot have multiple values or duplicate attributes.
If repeated attributes appear, you may need to define a new entity. The new entity is composed of repeated attributes. There is a one-to-many relationship between the new entity and the original entity. The first normal form pattern requires that the attribute value cannot be split into smaller parts, that is, the attribute item cannot be a combination of attributes or consist of a set of attributes.
In short, the first normal form is non-duplicate columns. For example, if a table consists of "employee number", "name" and "phone number" (a person may have an office phone and a mobile phone), then normalizing it to 1NF can divide the phone number into "office phone" and "phone number". "Mobile phone" has two attributes, namely employee (employee number, name, office phone, mobile phone).
2. 2NF (Second Normal Form)
The second normal form (2NF) is established on the basis of the first normal form (1NF) , that is, to satisfy the second normal form (2NF), you must first satisfy the first normal form (1NF). Second Normal Form (2NF) requires that each instance or row in a database table must be uniquely distinguishable. To achieve differentiation, it is usually necessary to add a column to the table to store the unique identifier of each instance.
If the relational model R is in the first normal form, and each non-primary attribute in R is completely functionally dependent on a candidate key of R, then R is called the second normal form schema (if A is the relational schema R If it is an attribute of the candidate key, A is said to be the primary attribute of R, otherwise A is said to be a non-primary attribute of R).
For example, in the course selection relationship table (student number, course number, grades, credits), the keyword is a combination keyword (student number, course number), but since the non-primary attribute credit only depends on the course number, There is only partial dependence on keywords (student ID, course ID), but not complete dependence. Therefore, this method will lead to problems such as data redundancy and update anomalies. The solution is to divide it into two relational models: student table (student table) number, course number, scores) and course schedule (course number, credits), the new relationship is connected through the foreign keyword course number in the student table, and is connected when needed.
3. 3NF (Third Normal Form)
If the relational model R is in the second normal form, and each non-primary attribute is not transferred If the candidate key depends on R, R is said to be in third normal form.
Take the student table (student number, name, course number, grades) as an example. There are no duplicate student names, so the table has two candidate codes (student number, course number) and (name, course number). number), so there is functional dependence: student number ——> name, (student number, course number) ——> grade, the only non-primary attribute grade has no partial dependence on the code, and there is no transitive dependence, so the attribute Belongs to the third paradigm.
4. BCNF (BC normal form)
It is built on the basis of the third normal form. If the relational model R is the first normal form, And each attribute does not pass a candidate key that depends on R, then R is called a BCNF schema.
Assuming that the warehouse management relationship table (warehouse number, storage item number, administrator number, quantity) satisfies an administrator to only work in one warehouse; a warehouse can store multiple items, then the following relationship exists:
(warehouse number, storage item number)——>(administrator number, quantity)
(administrator number, storage item number)——>(warehouse number, quantity)
So, (warehouse number, storage item number) and (administrator number, storage item number) are candidate codes for the warehouse management relationship table. The only non-key field in the table is quantity, which is consistent with the third paradigmatic. However, due to the following decision relationship:
(warehouse number)——>(administrator number)
(administrator number)——>(warehouse number)
That is, there is a situation where the key field determines the key field, so it does not comply with BCNF. Decompose the warehouse management relationship table into two relationship tables: warehouse management table (warehouse number, administrator number) and warehouse table (warehouse number, storage item number, quantity), so that this database table complies with BCNF and eliminates deletion exceptions , insertion exception and update exception.
5. 4NF (Fourth Normal Form)
Suppose R is a relational model, and D is a set of multi-valued dependencies on R. If there is a multi-valued dependency on X->Y in D, X must be a superkey of R, then R is said to be in the fourth normal form.
For example, employee table (employee number, employee's child name, employee elective courses). In this table, the same employee may have multiple employee child names. Similarly, the same employee may also have multiple employee names. An elective course for employees, that is, there are multi-valued facts here, which does not conform to the fourth paradigm. If you want to comply with the fourth normal form, you only need to divide the above table into two tables so that they have only one multi-valued fact, such as employee table one (employee number, employee's child name), employee table two (employee number, employee elective course) , both tables have only one multi-valued fact, so they conform to the fourth normal form.
1. First Normal Form (1NF)
In any relational database, the first normal form (1NF) is the basic requirement for the relational model. If it does not meet the first normal form (1NF) 1NF) database is not a relational database.
The so-called first normal form (1NF) means that each column (that is, each attribute) of the database table is an indivisible basic data item, and there cannot be multiple values in the same column, that is, in the entity An attribute of can not have multiple values or duplicate attributes. In short, first normal form is a column without duplicates.
2. Second Normal Form (2NF)
The second normal form (2NF) is established on the basis of the first normal form (1NF), that is, it satisfies the The second normal form (2NF) must first satisfy the first normal form (1NF). Second Normal Form (2NF) requires that each instance or row in a database table must be uniquely distinguishable. To achieve differentiation, it is usually necessary to add a column to the table to store the unique identifier of each instance. The employee number (emp_id) column is added to the employee information table, because each employee's employee number is unique, so each employee can be uniquely distinguished. This unique attribute column is called the primary key or primary key or primary key.
Second Normal Form (2NF) requires that the attributes of an entity completely depend on the primary key. The so-called complete dependence means that there cannot be an attribute that only depends on part of the primary key. If it exists, then this attribute and this part of the primary key should be separated to form a new entity. The new entity and the original entity are one-to-many. relation. To achieve differentiation, it is usually necessary to add a column to the table to store the unique identifier of each instance. In short, the second normal form is that non-primary attributes depend on the primary key.
3. Third Normal Form (3NF)
To satisfy the third normal form (3NF), you must first satisfy the second normal form (2NF). On the basis of satisfying the second normal form, there must be no transitive functional dependence, then it is the third normal form. In short, the third normal form is that attributes do not depend on other non-primary attributes.
The above is the detailed content of How much do you know about the four database paradigms?. For more information, please follow other related articles on the PHP Chinese website!
Securing MySQL Default Installations and ConfigurationsJul 24, 2025 am 02:06 AMModifying the default root password, deleting anonymous users, banning remote root login, removing test databases, and restricting access ports are key steps in MySQL security hardening. First, use the ALTERUSER command to set a strong password and avoid using the root account to connect to the application; secondly, delete anonymous users'@'localhost' and ''@'your_hostname' through DROPUSER; then check and delete the 'root'@'%' account that allows remote login, or create a restricted dedicated account instead; then delete unnecessary test databases and other irrelevant data; finally restrict port 3306 access through firewall tools, or set bind-addres in the configuration file
Understanding MySQL Indexes for WHERE, ORDER BY, GROUP BYJul 24, 2025 am 02:05 AMMySQL indexes are not as fast as possible, and they need to be used reasonably according to the query scenario. 1. The WHERE condition medium value query (=) has the best effect. The range query must comply with the principle of leftmost prefix. Fuzzy match LIKE'abc%' can be indexed, LIKE'�c' is not available, and functions or expressions are avoided in the condition. 2. ORDERBY needs to use indexes to avoid file sorting. It requires that the sorting columns have indexes and the WHERE and ORDERBY columns are in the same order to form a joint index, but range query may cause the sorting to be invalid. 3. GROUPBY recommends using an existing index structure, which prioritizes indexes covering equivalent conditions. Discontinuous columns or inappropriate order will add additional overhead. In addition, the EXPLAIN tool should be paid attention to the implementation plan
Troubleshooting MySQL Replication Sync IssuesJul 24, 2025 am 02:03 AMCommon solutions to the MySQL master-slave synchronization problem are as follows: 1. Check whether the master-slave connection is normal, check the error information of the Last_IO_Error and Last_SQL_Error fields to ensure that the main library port is open and the slave library account has REPLICATIONSLAVE permission; 2. Check whether there are SQL execution errors, if the table does not exist or the field type does not match, skip the error and continue synchronization if necessary; 3. Fix data inconsistency, resynchronize full amount through mysqldump or PerconaXtraBackup, or use pt-table-checksum to detect and repair differences; 4. Optimize configuration and adjust sync_binlog and slave_parall
Choosing the Right MySQL Storage Engine: InnoDB vs MyISAM RevisitedJul 24, 2025 am 02:02 AMInnoDB is suitable for scenarios where transactions, foreign keys, and row-level locks are required. 2. MyISAM is suitable for scenarios where more reads, less writes, and 3. Modern MySQL recommends using InnoDB by default. InnoDB supports transaction processing, crash recovery, foreign key constraints and row-level locking, and is suitable for scenarios with high data consistency requirements such as financial transactions and order processing, with good concurrency performance and high reliability; MyISAM is simple in design and fast query speed, suitable for scenarios where reading operations are mainly based on log statistics and report analysis, but write operations will lock the entire table, affecting concurrency performance; Since MySQL5.5, InnoDB has become the default engine, and continues to obtain new functions and is more applicable. Unless there are special needs, it is recommended to choose InnoDB to avoid late migration costs.
Troubleshooting MySQL Replication User PrivilegesJul 24, 2025 am 01:58 AMMySQL master-slave replication issues are usually caused by improper configuration of replication user rights. 1. Make sure that the replica user has REPLICATIONSLAVE permissions, which can be checked through SHOWGRANTS and added with the GRANT command; 2. Avoid over-authorization and only grant necessary permissions such as REPLICATIONSLAVE and REPLICATIONCLIENT; 3. Check whether the permissions are effective, confirm that there are no spelling errors, FLUSHPRIVILEGES has been executed, the database modification is correct, and MySQL restart is restarted; 4. If the error "Accessdeniedforuser" is reported, the user name and password host should be confirmed, the user existence, firewall and port connectivity should be confirmed.
Optimizing MySQL for Social Media PlatformsJul 24, 2025 am 01:56 AMTooptimizeMySQLforsocialmediaplatforms,startwithindexingstrategies,schemadesign,queryoptimization,andconnectionhandling.1)Usecompositeandcoveringindexeswiselytospeedupquerieswithoutslowingdownwrites.2)Normalizecoredataforconsistencyanddenormalizesele
Optimizing MySQL for Gaming Leaderboards and Player StatsJul 24, 2025 am 01:44 AMTooptimizeMySQLforgamingleaderboardsandplayerstats,useproperdatatypesandindexing,optimizequerieswithwindowfunctions,implementcaching,andconsiderpartitioningorshardingatscale.First,useINTorBIGINTforscoresandDECIMALforfractionalvalues,andapplycompoundi
Securing MySQL Administrative Interfaces and ToolsJul 24, 2025 am 01:41 AMTo avoid exposing the management interface to the public network, it should be accessed through SSH tunnels or intranets; 2. Use a dedicated account and strictly control permissions, disable root remote login; 3. Enable SSL encryption transmission, set strong password policies and cookie authentication; 4. Regularly update the MySQL version and monitor log audit operations. If the MySQL management interface is not protected properly, it should restrict access methods, strengthen authentication, encrypt communications and continuously monitor security status.


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.







