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');
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
}
);
Thank you for reading my blog, Please check my other stories too🤗
If you like my work, you can buy me a coffee ☕