Relational and Non-relational Database
Published:
This is my personal notes for relational and non-relational database.
Relational Database
- MySQL, PostgreSQL, Oracle, SQL Server
Relational Database stores data in DataBase Tables with Primary Key, Index etc.
Example:
学号 | 姓名 | 性别 | 生日 |
123 | 张三 | 男 | 1990年1月1日 |
Advantage: 如果要插入数据, 需要定义好表结构, 主键, 索引等后才能插入,所以数据结构中途有较大变更的话会变得麻烦
Disadvantage: 但是这种形式让我们可以使用join方式跨多表查询
But, if you’re dealing with a phenomenally huge amount of data, it can be way too tedious, and the probability of error (in the form of an ORM Impedance Mismatch issue) increases. In that situation you may need to consider going with a non-relational database. A non-relational database just stores data without explicit and structured mechanisms to link data from different tables (or buckets) to one another.
Non-relational Database
- MongoDB, Redis, CouchBase
Non-Relational Database stores data in Form of Key-Value, like JSON.
{
学号: 123
姓名: 张三
性别: 男
生日: 1990年1月1日
增加项目:[
{成绩: 99}
]
}
- Advantage: 在Non-relational Database中,插入数据变得方便而快速,不需要SQL层的解析
db.tablename.insert(
{
学号: 234
姓名: 李四
性别: 男
生日: 2000年1月1日
}
)
- Disadvantage: 但是跨表查询难以实现,没有类似join的功能