Introduce to RDBMS and SQL
- Liu, An-Chi 劉安齊
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):
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 has many attributes, and one is
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. Generally 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):
You can see there are tables in a database which is for a model.
This series is just for implementing a RDBMS, StellarSQL.
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
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.
This may help me earn some money. (Of course you can donate me directly)
可以去 全站留言板 來留言喔！