iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 6
1

5: Introduce to RDBMS and SQL

2018/10/20

It's recommended to read the article on Gitbook for a better experience.

It is very sad to say that, I have spent more than ten hours fighting with Tokio.rs from yesterday. I am going to write today's article and go back to continue programming.

Today, I will talk about RDBMS and SQL.

Entity Model

Before SQL, you should understand what is entity relationship (ER) model. The ER model is first introduced by 陳品山 (Peter P.S Chen) in 1976. In short, it is a model for organizing data with many relationships. There is an introduction on Wikipedia. A ER diagram is a visualization way for a ER model.

A ER diagram looks like (source: Wikipedia):

ER diagram

As you can see, there the rectangles are entities, and entities have relationships which are diamonds. There are also ovals which are attributes for entities.

For example in the figure, Character is a entity, it has a relationship Has to an another entity Account. Account has many attributes, and one is AccName.

RDBMS

With ER model, we can define all data in the real world into a model. Then, we can use the model to create a database. A relational database is based on ER model, and a RDBMS is a DBMS for relational database.

Assume we have a ER model (maybe a model for a company), we will transfer the model into the format of relational database. General speaking for RDBMS, a database is for a model. There would be tables in a database. A table is a partial relationship of entities in the model, and all tables can make up a complete model.

It will somehow looks like this (source: Wikipedia):

tables

You can see there are tables in a database which is for a model.

This series is just for implementing a RDBMS, StellarSQL.

SQL

Now we know what is a RDBMS. However, we need a method for creating database, reading data, searching data, or creating relationships for data. So we introduce the SQL, which means Structured Query Language. SQL is designed for programs and management systems processing data. It is particularly useful in handling structured data where there are relations between different entities/variables of the data.

There is a math for supporting SQL, which is relational algebra. It is because the math that we can ensure SQL could handle data well.

SQL is a language. I will talk about the syntax later. Just take a look for now.

For example, the following SQL statement selects all the customers from the country "Mexico", in the customers table.

SELECT * FROM customers
WHERE country='Mexico';

Note that SQL is just like human speaking, so it is quite straightforward.

The modules for parsing SQL and processing SQL command on StellarSQL will be very important and also not easy, so I would need spend many time on it in the following days. (I am afraid that I don't have enough time)

That's all for today. If you have some time, I recommend you search some articles about ER model and ER diagram.


Quick Link
1.StellarSQL Repository
2.Gitbook of this series

Author
Liu, An-Chi (劉安齊). A software engineer, who loves writing code and promoting CS to people. Welcome to follow me at Facebook Page. More information on Personal Site and Github.


上一篇
StellarSQL 4: Client/Server Communication Implementation
下一篇
StellarSQL 6: Client/Server Communication Implementation(2)
系列文
Let's build a DBMS: StellarSQL -- a minimal SQL DBMS written in Rust30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言