SQL and NoSQL Database

Navya
2 min readFeb 5, 2023

--

The basic difference between structural and non-structural databases.

SQL and NoSQL

What is a Database?

A Database is a collection of organized data stored.

Example: An employee database of the company contains employee personal, educational, department, and salary details.

What is a Relational or SQL Database?

  • The data is stored as database objects called tables.
  • A table is a collection of rows and columns and its have a fixed schema.
  • Rows: A row is also called a tuple or record that holds different data within the same structure.
  • Columns: The column also called an attribute holds particular attribute information and properties that define datatypes such as varchar, and an integer with range.
  • Two or more tables can relate to each other and such relations are one-to-one, one-to-many, and many-to-many.
  • Relational Database uses SQL(Structural Query Language) to create, store, update and retrieve data.
  • Examples: MySQL, Oracle, PostgreSQL, etc.
  • Sample SQL Query :
select id,salary from employee where age >= 35 and (designation = 'manager');
SQL Database

What is a Document or NoSQL Database?

  • In a document database, data is stored in separate documents.
  • Each document is independent of the others.
  • It's not mandatory it has a fixed schema.
  • For Example, In Customer2 document has the field “contact” but the Customer1 document may not have this field.
  • All information related to the document is stored in one place.
  • We can perform queries to retrieve just one document and no need to perform different join requests.
  • We can edit, insert, and delete documents.
  • Examples: MongoDB, Cassandra, Redis, CouchDB, etc.
  • Sample NoSQL DB Query :
db.employee.find({

"$and": [{
"age ":{ "$gte" : 35 }
},{ " (designation " : 'manager'
}]
},{
"id": 1,
"salary": 1
}
);
NoSQL Database

--

--

Navya

Motivator l Software Engineer I Movie freak l Enthuiastic Learner | Blogger