MySQL database, from entry to proficiency: the second part - the comparison between MySQL relational database and non-relational database


directory hierarchy

MySQL database, from entry to proficiency: Part 1 - Detailed explanation of MySQL concepts
MySQL database, from entry to proficiency: Part 2 - Comparison of MySQL relational database and non-relational database
MySQL database, from entry to proficiency: Part 3 Part - MySQL database specifications and basic query statements
MySQL database, from entry to proficiency: part four - commonly used operators in MySQL and their usage
MySQL database, from entry to proficiency: part five - MySQL sorting and
pagingMySQL Database, from entry to proficiency: Part 6—Comprehensively master MySQL multi-table query skills
MySQL database, from entry to proficiency:
Part 7—Application of MySQL single-row functions Aggregate Function Practical Exploration: Optimizing the SELECT Process to Help Efficiently Query
the MySQL Database, from Beginner to Master: Part 9 - MySQL Subquery
MySQL Database, from Beginner to Master: Part 10 - MySQL Table Creation and Management Guide
MySQL Database, from From entry to proficiency: Part 11 - Addition, deletion and modification guide for MySQL data processing
MySQL database, from entry to proficiency: Part 12 - Detailed explanation of MySQL data types
MySQL database, from entry to proficiency: Part 13 - MySQL Detailed Explanation of Data Table Constraints on
MySQL Database, From Beginner to Master: Part Fourteen——MySQL View Detailed Explanation of
MySQL Database, From Beginner to Master: Part Fifteen——Detailed Explanation of MySQL Stored Procedures and Functions on
MySQL Database, From Beginner to Master: Part 1 Sixteen articles——MySQL variables, process control and cursors explain
MySQL database in detail, from entry to mastery: Article seventeen——How to use MySQL triggers and precautions
MySQL database, from entry to proficiency: Part 18 - Full Analysis of New Features of MySQL 8

THIS IS END!


Foreword:

An important concept in computer science, a database is a software system for storing and managing data. In modern applications, databases play a vital role as they help us store, retrieve and process data efficiently. In the database world, relational and non-relational databases are the two most common types. This article will introduce the basic concepts and common types of these two databases, and explore the design rules of relational databases in depth.

Summary:

This article mainly introduces the basic concepts and common types of relational databases and non-relational databases, as well as the design rules of relational databases. In the field of databases, relational databases are the most common type, with advantages such as complex queries and transaction support. Non-relational databases are known for their high performance and low cost, and are suitable for scenarios such as log collection, leaderboards, and timers. When designing a relational database, you need to consider tables, records, fields, and the relationship between tables. This article also introduces the table building principles of one-to-one association, one-to-many association, many-to-many association and self-reference.

Part 2_Relational Databases and Non-Relational Databases

1. RDBMS and non-RDBMS

We can see from the rankings that relational databases are definitely the mainstream of DBMSs, and the most used DBMSs are Oracle, MySQL and SQL Server. These are relational databases (RDBMS).

1.1 Relational database (RDBMS)

1.1.1 Substance

This type of database is the oldest type of database, and the relational database model boils down complex data structures into simple
binary relationships (that is, in the form of two-dimensional tables).
insert image description here
A relational database stores data in the form of rows and columns for easy understanding by users. This series of rows and columns is called SQL, the query language of relational databases.
insert image description here

1.1.2 Advantages

Complex queries can use SQL statements to easily perform very complex data queries between one table and multiple tables.
Transaction support enables the realization of data access requirements with high security performance.

1.2 Non-relational database (non-RDBMS)

1.2.1 Introduction

A non-relational database can be regarded as a functionally castrated version of a traditional relational database. It stores data based on key-value pairs and does not need to be parsed by the SQL layer. The performance is very high. At the same time, performance is further improved by reducing less frequently used functions. At present, most of the mainstream non-relational databases are basically free.

1.2.2 What are the non-relational databases

Compared with SQL, NoSQL generally refers to non-relational databases, including key-value databases, document databases, search engines, and column stores on the list, as well as graph databases. Only by using the term NoSQL can these technologies be included.

Key-value database
Key-value databases store data in the form of Key-Value keys, where Key and Value can be simple objects or complex objects. As a unique identifier, Key has the advantage of fast search speed, which is obviously better than relational databases in this respect. The disadvantage is that it cannot use conditional filtering (such as WHERE) like relational databases. If you don't know where to find data, you need to Iterating over all keys consumes a lot of computation.

A typical usage scenario for a key-value database is as an in-memory cache. Redis is the most popular key-value database.
insert image description here
Document database
This type of database can store and obtain documents, which can be in formats such as XML and JSON. In a database, a document is the basic unit for processing information, and a document is equivalent to a record. The documents stored in the document database are equivalent to the "values" stored in the key-value database. MongoDB
is the most popular document database. In addition, there are CouchDB and so on. Although search engine databases use indexes to improve retrieval efficiency in relational databases, they are less efficient for full-text indexes. Search engine database is a form of data storage used in the field of search engines. Since search engines will crawl a large amount of data and store them in a specific format, the optimal performance can be guaranteed during retrieval. The core principle is "inverted index".

Typical products: Solr, Elasticsearch, Splunk, etc.

Columnar database
Columnar database is a database relative to row-based storage. Databases such as Oracle, MySQL, and SQL Server all use row-based storage
(Row-based), while columnar databases store data in the database in columns. The advantage of this is that it can greatly reduce the
I/O of the system, which is suitable for distributed file systems. The disadvantage is that the functions are relatively limited. Typical products: HBase, etc.
insert image description here
Graph database
A graph database, as its name implies, is a database that stores graph relationships. It uses graph data structure to store the relationship between entities (objects). Relational data is used to store data with clear relationships, but it is somewhat powerless for data storage with complex relationships. For example, the relationship between characters in a social network is very complicated if you use a relational database, but it will be very simple if you use a graph database.
Typical products: Neo4J, InfoGrid, etc.
insert image description here

1.2.3 Evolution of NoSQL

Since SQL has always dominated DBMS, many people are thinking about whether there is a database technology that can stay away from SQL, so NoSQL was born, but with the development, it is found that it is more and more inseparable from SQL. DBMSs in the NoSQL camp so far will have SQL-like functions. The following is the interpretation of the term "NoSQL" in different periods. From these changes in interpretation, we can see the evolution of NoSQL functions:

1970:NoSQL = We have no SQL
1980:NoSQL = Know SQL
2000:NoSQL = No SQL!
2005:NoSQL = Not only SQL
2013:NoSQL = No, SQL!

NoSQL makes a good supplement to SQL. For example, in actual development, there are many business needs. In fact, complete relational database functions are not required, and the functions of non-relational databases are sufficient. In this case, it is of course a wiser choice to use a non-relational database with higher performance and lower cost. For example: log collection, leaderboard, timer, etc.

1.3 Summary

There are many classifications of NoSQL. Even so, in the DBMS ranking, the SQL camp still has a larger proportion. 4 of the top 5 DBMSs are relational databases, and 12 of the top 20 DBMSs are relational databases. . Therefore, mastering SQL is very necessary. The entire set of courses will revolve around SQL.

2. Relational database design rules

There can be multiple tables in a database, and each table has a name to identify itself. Table names are unique.
Tables have properties that define how data is stored in the table, similar to the design of "classes" in Java and Python.

2.1 Tables, records, fields

There are three main concepts in the ER (entity-relationship, entity-relationship) model: entity set, attribute, and relationship set.
An entity set (class) corresponds to a table (table) in the database, and an entity (instance) corresponds to a row (row
) in the database table, also known as a record (record).
An attribute (attribute) corresponds to a column (column) in the database table , also known as a field (field).
insert image description here

ORM idea (Object Relational Mapping) embodies:
a table in the database <—>
a piece of data in a class table in Java or Python <—> a column in an object (or entity)
table in a class <--- -> A field, attribute (field) in a class

2.2 Relationship between tables

There is a relationship between tables and data records between tables. Various entities in the real world and various links between entities are
represented by relational models.
Four: one-to-one association, one-to-many association, many-to-many association, self-reference

2.2.1 One-to-one association (one-to-one)

There are not many applications in actual development, because one-to-one can be created as a table.
Example: Design student table: student number, name, mobile phone number, class, department, ID number, home address, place of origin, emergency
contact, ...

Split into two tables: the records of the two tables have a one-to-one correspondence.
Basic information table (commonly used information): student number, name, mobile phone number, class, department
File information table (infrequently used information): student number, ID number, home address, place of origin, emergency contact,…

Two table building principles:
unique foreign key: the primary key of the main table and the foreign key (unique) of the secondary table form a primary-foreign key relationship, and the foreign key is unique.
The foreign key is the primary key: the primary key of the primary table and the primary key of the secondary table form a primary-foreign key relationship.
insert image description here

2.2.2 One-to-many relationship

Common example scenarios: customer table and order table, category table and commodity table, department table and employee table.
Example:
employee table: number, name, ..., department Department
table: number, name, introduction
One-to-many table building principle: create a field in the slave table (multi-party), and the field serves as a foreign key pointing to the primary key of the main table (one party)insert image description here

insert image description here

2.2.3 Many-to-many

To represent a many-to-many relationship, a third table must be created, often called a join table, which divides the many-to-many relationship into two one-to-many relationships. Insert the primary keys of both tables into the third table.
insert image description here
Example 1: Student-Course
Student information table: one line represents a student's information (student number, name, mobile phone number, class, department...)
Course selection information table: a student can choose multiple courses, and a course can be used by multiple student choice

学号 课程编号
1 1001
2 1001
1 1002

Example 2: Product-Order The
"Orders" table and the "Products" table have a many-to-many relationship defined by establishing two one-to-many relationships with the "Order Details" table
. An order can have multiple products, and each product can appear in multiple orders.
Products table: Each record in the Products table represents a product.
Orders table: Each record in the Orders table represents an order.
Order details table: Each product can correspond to multiple records in the "Order" table, that is, it appears in multiple orders. An order
can correspond to multiple records in the "Products" table, that is, it contains multiple products.
insert image description here
Example 3: User-role
many-to-many relationship table building principle: A third table needs to be created, with at least two fields in the middle table, and these two fields are used as foreign keys to point to their
respective primary keys.

2.3.4 Self reference

insert image description here

Guess you like

Origin blog.csdn.net/qq_42055933/article/details/131138936