Which database is better? Sql Or NoSql?

A database is just a collection of records. Database management systems are designed to deal with records.

Database Management allows you to deal with records by running queries. There are different types of databases as below:

  • Hierarchical databases.
  • Network databases.
  • Relational databases.
  • Object-oriented databases
  • Non-relational or Distributed database

In this tutorial we will work with relational or non-relational databases. If you want to learn about remaining types checkout following article:

Different types of databases

What is relational database?

A relational database is a type of databse that allow us to identify and access data in relation to other data stored in the database.

Data in relational database is organized into tables. Tables can have hundreds, thousands, sometimes even millions of rows of data. These rows are often called records.

Tables can also have different attributes which are reffered to as columns. Column allow us to store specific type of data in the table.

A relational database management system (RDBMS) is a program that allows you to create, update, and administer a relational database.

Relational databases require that schemas be defined before you can add data. A schema is basically a defination of a table and columns.

Schema contains information about what types of data is stored in each column of a table.

For example, you might want to store data about your customers such as phone numbers, first and last name, address, city and state – a SQL database needs to know this in advance.

RDMS uses SQL as a query language to deal with CRUD operations.

SQL (Structured Query Language) is a programming language used to communicate with data stored in a relational database management system.

Followings are some of the example of RDMS:

Finally, to write in brief relational database store data in table format. Tables can grow large in size.

What is non-relational or no-sql database?

A NoSQL refers to "non SQL" or "non relational" which does not store or retrive data from tabular structured compared to relational databases.

NoSQL databases have variety of different types. Followings are some of the example:

  • Column
    • HBase
    • Cassandra
  • Document
    • CouchDB
    • MongoDB
    • Couchbase
  • Key-value
    • Dynamo
    • Redis
    • Memcached
  • Graph
    • ArangoDB
    • Neo4j

In this tutorial, I am not going over each of above types rather I would like to compare SQL vs NoSQL.

SQL Vs NoSQL

Relational database comes with single type with minor variations however NoSQL databases comes in different variety.

Some of the example of relational databases are MySQL, Postgres and Oracle. In relational database data is stored in tabular format using rows and columns.

Some of the example of NoSQL databases are MongoDB, Redis, Cassandra, HBase, Neo4j. NoSQL databases do not store data in tabular format rather they store them as key value pair or in document in json or xml format.

Relational database needs to have schema defined in order to use them however NoSQL databases are schema less.

In relational database it scales vertically meaning a single server must be made to handle large data and adding more memory on top as required. It is possible to scale relational database however it comes with high cost of building such infrastructure.

In NoSQL database it can easily grow horizontally by adding more servers. Verticle scaling is also not issue with NoSQL databases.

Relational databases can be open or closed source however NoSQL databases are open source.

Relational database uses SQL language to deal with database however NoSQL uses object -oriented API's.

Often, organizations will begin with a small-scale trial of a NoSQL database in their organization, which makes it possible to develop an understanding of the technology in a low-stakes way.

There are many NoSQL databases, though MongoDB is widely recognized as the leading NoSQL database.

Resources

Above contents are taken from following resources:

https://www.mongodb.com/nosql-inline