ニュース・ブログ

ニュース・ブログ一覧インフラの記事情報Everything About SQL and NoSQL

Everything About SQL and NoSQL

Everything about SQL & NoSQL

As cloud technology is getting cheaper year by year, it’s time we learn about NoSQL and cloud technologies. To understand NoSQL, first we have to know about SQL too.

SQL

So when you have a lot of information about things, like customer’s phone number and name etc, you store it in a database. A database is a place where you store your data.
So when you get data or change data from that database, you need some way to access that information. We do that with something called SQL. 
S = structured 
Q = Query
L = language. 
From that definition you can infer this is a language which you use for querying(for all kind of changes, like create, read, edit, delete, ) the database in a structured way. You have to ask in a structured way because they are dumb machines and don’t understand our informal language.

 

Structured Query Language is used in relational database. So what is relational database ? Look at the example below :

Relational database example

You can see that there’s table called WORKER which has a lot of information about workers like name, age, address etc. Also there is two more tables one is ADDRESS and SALARY . So WORKER table is linked with ADDRESS and SALARY table. Because it’s linked you can track every worker’s address and salary from the WORKER table.

NoSQL

So but there is another popular way, where you don’t use the SQL, because you don’t store data in relational database. That’s called NoSQL database.

The definition from Wikipedia is well on the spot, it says 

A NoSQL (originally referring to “non-SQL” or “non-relational”) database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.

In NoSQL so you don’t get a lot of features like you get from a relational database so non-relational. Also you don’t usually use SQL for this so non-SQL.
So why use NoSQL when you can’t use the benefits of the relational databases ?
Because, what you get by giving up some of these handy features is improved performance, availability and scalability.

 

A an example of document(JSON) structure of NoSQL database’s (MongoDB) looks like this :

NoSQL database structure(JSON)

In NoSQL you get data in a blob like the above image. So if it was a relational database/SQL database, there would be a different table for genre and stars . But in SQL you can save your data in a blob.

Key components of SQL and NoSQL

4 key components of SQL

key components of SQL

 

4 key components of NoSQL

key components of NoSQL

 

SQL Structure :

SQL has multiple tables which you can connect with each other , so there is a relation. The relation part is already explained above. Because of this, you can create very custom queries which is very useful for unique situations or for analysis. 

Also you can constraint the data type so that any malformed data can’t be saved in the database.

NoSQL Structure :

NoSQL structure is implement depended. There are table, document(JSON), graph like databases. All these rely on key store values to store data. So you need key to query your NoSQL database.

As you only search here with key value, you can data quicker than SQL database.

 

SQL Storage:

Usually in a relational database engine there is only node which contains the entire copy of the database. You can use advanced strategy so that there are multiple copy of the database which can support if there are a lot of users accessing at the same time.

NoSQL Storage:

NoSQL database engine divides data in multiple node by hashing the key. In short you have multiple nodes which contain your data. 
So your database can support more user compared to SQL database.

 

SQL Scale:

To scale here, either you have to add better machines or more machines.

NoSQL Scale:

In NoSQL you just have to increase your nodes which you can be done by increasing memory , CPU, disk storage.

 

SQL Access:

You can access data here by using raw SQL if you have database connection. For example : select * from table

Nowadays, most people use ORM (Object Relational Mappers ) which are abstractions of SQL queries. It’s easy to make queries with ORM

NoSQL Access:

You can use REST API’s to get data or optionally you can do CRUD operations in vendor specific language.

You can see all the list of other articles here.

You can learn here about Amazon DynamoDB which is a NoSQL database Amazon DynamoDB.

 

 

週間ブログランキング