Various dbms

What are the differences

Posted by Eirik on 23 Feb, 2024

Relational Databases:

Structured Data: Data is organized in tables with predefined structures, each table consisting of fixed columns and column types.

SQL Query Language: Relational databases typically use SQL (Structured Query Language) for executing queries and managing data.

Strong Consistency: They usually provide ACID (Atomicity, Consistency, Isolation, Durability) properties, ensuring data consistency and reliability.

Vertical Scaling: They often employ vertical scaling, meaning adding more hardware resources to improve performance.

Example Systems:

  • MySQL
  • PostgreSQL
  • Oracle Database
  • Microsoft SQL Server
  • SQLite

Non-relational Databases (NoSQL):

Flexible Schema: Data can be stored in various ways such as documents, graphs, key-value pairs, etc., and the structure can be adjusted flexibly.

NoSQL Query Language: Each NoSQL database may use different query languages or APIs for accessing and manipulating data.

Eventual Consistency: They typically provide eventual consistency, meaning data becomes consistent after a certain period.

Horizontal Scaling: They usually achieve performance improvements through horizontal scaling, i.e., adding more nodes to increase processing capacity.

Example Systems:

  • MongoDB
  • Cassandra
  • Redis
  • Amazon DynamoDB
  • Couchbase
  • These are two different types of databases, each with its own advantages and disadvantages in different application scenarios. The choice of which type of database to use depends on the application requirements, data structure, expected scalability, and other factors.

關聯式資料庫和非關聯式資料庫(通常是指NoSQL資料庫)在設計和使用上有著一些顯著的差異。以下是它們之間的主要區別以及各自的系統示例:

關聯式資料庫:

結構化資料: 資料以表格的形式組織,每個表格有預先定義的結構,包含固定的列和列的類型。

SQL查詢語言: 關聯式資料庫通常使用SQL(Structured Query Language)來執行查詢和管理資料。

強一致性: 通常提供ACID(原子性、一致性、隔離性、持久性)特性,確保資料的一致性和可靠性。

垂直擴展: 通常採用垂直擴展,即增加更多的硬體資源來提高性能。

示例系統:

  • MySQL
  • PostgreSQL
  • Oracle Database
  • Microsoft SQL Server
  • SQLite

非關聯式資料庫(NoSQL):

彈性模式: 資料可以以各種不同的方式儲存,例如文檔、圖形、鍵值對等,並且可以彈性地調整結構。

NoSQL查詢語言: 每種NoSQL資料庫可能使用不同的查詢語言或API來存取和操作資料。

最終一致性: 通常提供的是最終一致性,即在一段時間後資料會變得一致。

水平擴展: 通常通過水平擴展來提高性能,即增加更多的節點以增加處理能力。

示例系統:

  • MongoDB
  • Cassandra
  • Redis
  • Amazon DynamoDB
  • Couchbase

這些是兩種不同類型的資料庫,它們在不同的應用場景中有著各自的優缺點。選擇使用哪種類型的資料庫取決於應用的需求、資料的結構、預期的擴展性以及其他因素。

Data Base Normalization

Make the database cannot express redundant data.

The normal forms (safety level)

From very danger to very safe:

在資料庫正規化中,1NF(第一正規化)到5NF(第五正規化)代表了不同程度的資料庫表結構優化。以下是它們之間的差異,以及每個階段的例子和簡要說明:

第一正規化(1NF, minimun safety level):

  1. Using row order to convey information is not permitted
  2. Mxing data types within the same column is not permitted
  3. Having a table without a primary key is not permitted
  4. Repeating groups are not permitted

確保每個資料庫表中的每個欄位都是原子性的,即每個欄位只包含單一值。 例子:考慮一個訂單表格,每個訂單可能有多個商品,如果將商品以逗號分隔存儲在單個欄位中,這樣的訂單表就不符合1NF。應將商品拆分為獨立的行。

第二正規化(2NF):

Each non-key attribute must depend on the entire primary key

  • Avoid deletion anomoly and update anomoly

要求每個非主鍵欄位(non-key column)完全依賴於主鍵(key column),並且不依賴於其他非主鍵欄位。 例子:在訂單表格中,如果有商品描述和價格等欄位,但這些資訊僅與商品ID有關,則應該將商品描述和價格移至商品表格。

第三正規化(3NF):

Every non-key attribute in a table must depend on the key, the whole key, and nothing but the key. 要求移除非主鍵欄位之間的傳遞依賴,即如果一個非主鍵欄位依賴於另一個非主鍵欄位,則應將其移至另一個表格。 例子:在訂單表格中,如果有客戶地址和郵政編碼,但這些資訊僅與客戶ID有關,則應將客戶地址和郵政編碼移至客戶表格。

Boyce-Codd正規化(BCNF):

Every attribute in a table must depend on the key, the whole key, and nothing but the key. 類似於第三正規化,但對於特定情況下的多個候選鍵也進行了處理。 例子:當資料庫表格具有多個候選鍵時,BCNF確保每個非主鍵屬性完全依賴於每個候選鍵,而不僅僅是某些候選鍵。

第五正規化(5NF):

The table(which must be in 4NF) cannot be describe as the logical result of joining some other table s together. 進一步分解表格以消除多值依賴,即表格中的某些欄位值取決於另一個欄位的多個值組合。 例子:如果一個資料表格包含一個欄位記錄每個客戶的所有電話號碼,但不同類型的電話號碼(家庭、辦公室、手機等)以不同的方式存儲,則可以將這些多值依賴分解為獨立的表格。

Data integrity

Data cannot be trust, because it disagree with itself (e.g, 2 bithday of a person)