【Database】Analysis of relational database and non-relational database

【Database】Analysis of relational database and non-relational database

1 Introduction

An easy-to-understand metaphor: relational databases are similar to Excel, and non-relational databases are similar to word. Which one to use depends on what data you want to edit and process.

  • Relational database: A database that stores data in tables, with a two-dimensional table as the data structure. The relationship between tables and field types needs to be clearly defined, with SQL statements as operating instructions, also known as SQL databases. Mainstream relational databases include Oracle, MySQL, SQL Server, Microsoft Access, DB2, etc.
  • Non-relational database: A database that does not use a tabular schema of rows and columns like relational databases. Instead, its storage model is optimized for the type of data it stores. Not only SQL statements can be used as operation instructions, but other types of query languages ​​can also be used, also known as NoSQL (Not only SQL) databases, which do not need to pre-define the schema of key data, and are more flexible than SQL databases. The mainstream NoSQL databases include Redis, MongBD, Hbase, CouhDB, etc.

insert image description here

2. Relational database

  • Relational database: A database that stores data in tables, with a two-dimensional table as the data structure. The relationship between tables and field types needs to be clearly defined, with SQL statements as operating instructions, also known as SQL databases.

Common relational databases:

  • SQLServer: A relational database management system developed by Microsoft Corporation.
    • Advantages: Not open source, they provide multiple versions with different features for different users. Has a rich user interface and can handle large amounts of data.
    • Disadvantages: Traditional database operations are frequent and easily interrupted, and the amount of data is large and the load is also heavy.
  • MySQL: Released in 1995.
    • Pros: Open source, has lots of documentation and online support.
    • Disadvantages: The scale is not large, and it is easy to be interrupted when the data volume is over-operated too frequently.
  • PostgreSQL: Released in 1996.
    • Advantages: Open source, database based on object-relational model, it is not just a relational database, users can expand their functions by themselves.
    • Disadvantages: The operation of expanding functions is more complicated, and it is not easy for novices to get started. It is better to use non-relational databases directly. There are not as many included documents as MySQL.

3. Non-relational databases

  • A database that does not use a tabular schema of rows and columns like a relational database. Instead, its storage model is optimized for the type of data it stores. Not only SQL statements can be used as operation instructions, but other types of query languages ​​can also be used, also known as NoSQL (Not only SQL) databases, which do not need to pre-define the schema of key data, and are more flexible than SQL databases.

Common types of NoSQL databases are:

  • Document-oriented databases (Document-oriented databases): information used to store, manage, and retrieve documents. Data can be quickly queried in massive databases. e.g. MongoDB, CouchDB
  • Key-Value Stores: This is a database that uses distinct keys, where each key is associated with only one value in the collection. Think of it like a dictionary. One of the simplest NoSQL database types, such as Redis, Tokyo Cabint.
  • Distributed database (Wide-Column Stores): Use tables, rows, and columns, but unlike relational databases, the names and formats of columns may be different between rows in the same table, which makes up for the lack of scalability of SQL databases.
  • Graph Stores: Use graph structures for semantic queries with nodes, edges, and attributes to represent and store data. (ongdb, neo4j)

Common non-relational databases:

  • MongoDB: It is a document storage database and the most popular NoSQL database engine currently in use.
    • Pros: It uses json-like documents to store data and supports running on multiple servers. MongoDB allows for automatic sharding, a type of database partitioning that divides very large databases into smaller, faster, more manageable parts called data shards. It's easy to set up and get started, and there's plenty of professional support.
    • Disadvantage: is that they do not allow joins to be used to combine data or rows based on common fields between two or more tables. MongoDB does have a LOOKUP function, and users are officially advised not to rely on them.
  • Redis: The remote dictionary server is a key-value store.
    • Pros: It supports different kinds of abstract data structures like strings, lists, maps, sets, sorted sets, etc. It's also open source. Not only supports multiple data types, but also easy to install.
    • Cons: Same as above, does not allow joins to be used to combine data or rows based on common fields between two or more tables. And need to master the Lua programming language (a high-level scripting language)

4. Difference

4.1 Different data storage methods

The main difference between relational and non-relational databases is: the way data is stored .

  • Relational data is inherently tabular and thus stored in rows and columns of a data table. Data tables can be associated with each other and stored collaboratively, and it is also easy to extract data.
  • In contrast, non-relational data does not fit into rows and columns of tables, but is grouped together in large chunks. Non-relational data is usually stored in datasets, like documents, key-value pairs, or graph structures. Your data and its characteristics are the number one influencing factor in choosing how to store and extract your data.

4.2 Different expansion methods

The biggest difference between SQL and NoSQL databases may be in the way of expansion. To support the growing demand, of course, expansion is required. In order to support more concurrency,

  • SQL databases scale vertically, which means increasing processing power and using faster computers so that the same data set can be processed faster. Because data is stored in relational tables, performance bottlenecks in operations may involve many tables, which need to be overcome by improving computer performance. Although the SQL database has a lot of room for expansion, it will eventually reach the upper limit of vertical expansion.
  • NoSQL databases, on the other hand, scale horizontally. Because non-relational data storage is naturally distributed, the expansion of NoSQL databases can share the load by adding more common database servers (nodes) to the resource pool.

4.3 Different support for transactional

If data operations require high transactionality or complex data queries need to control the execution plan, then the traditional SQL database is your best choice in terms of performance and stability.

  • SQL database supports fine-grained control over transaction atomicity, and it is easy to roll back transactions.
  • Although NoSQL databases can also use transaction operations, they cannot compare with relational databases in terms of stability, so their real value lies in the scalability of operations and the processing of large amounts of data.

4.4 Summary

To summarize the difference between relational and non-relational databases:

  • A relational database stores data in rows and columns, like a spreadsheet, while a non-relational database does not store data in rows and columns, using the storage model that best suits the type of data it is storing (one of the four storage models one).

How to determine what database you want to use:

  • If the data you want to process is more suitable to be represented by rows and columns, use a relational database; if it is more suitable to store in a flexible space, use a non-relational database.
  • If the data set is small/medium and requires intensive read/write operations, use a relational database, and if you need to flexibly change the data type, use a non-relational database.

reference

【1】https://blog.csdn.net/caicau/article/details/119214130
【2】https://blog.csdn.net/weixin_51468875/article/details/114087402

Guess you like

Origin blog.csdn.net/qq_51392112/article/details/131353186