owned this note
owned this note
Published
Linked with GitHub
# SQL vs NoSQL databases

---
**What's the difference?** :cold_sweat:
* SQL databases are relational (defines relationships in the form of tables.)
* noSQL databases are non-relational/distributed (do not require a fixed schema, avoids joins)
---
**SQL** databases use structured query language (SQL) for defining and manipulating data & are table-based. SQL requires that you use predefined schemas to determine the structure of your data before you work with it. In addition, all of your data must follow the same structure. :nail_care:
---
**noSQL** database, on the other hand, has dynamic schema for unstructured data, and data is stored in many ways: it can be column-oriented, document-oriented, graph-based or organized as a KeyValue store. Does not require a particular query language. :frowning:
---
**Examples**
**SQL** --> Oracle, Postgres, and MS-SQL
**noSQL** --> MongoDB, Redis, Neo4j, Cassandra, Hbase
---
## Examples of the data structure of SQL and NoSQL databases
---

---

---
### SQL
---
1. Relational database in tabular format (rows and columns)

---
2. Online analytical processing, or OLAP uses multidimensional data 
---
### NoSQL
---
1. A column family containing 3 rows. Each row contains its own set of columns.

---
2. A graph database is essentially a collection of nodes and edges. Each node represents an entity (such as a person or business) and each edge represents a connection or relationship between two nodes.
---

---
3. Document database

---
4. Key - Value 
---
## Pros and cons of SQL and NoSQL databases
https://www.softwaretestinghelp.com/sql-vs-nosql/
---
| SQL | NoSQL |
| -------- | -------- |
| -/+ fixed data structure | + flexible data structures |
| + normalized data | - redundant data |
| + standard and powerful query language | - no standard interface, less powerful queries |
---
| SQL | NoSQL |
| -------- | -------- |
| + commercial and community support due to age of the technology | - less support |
| + code free | + hierarchical data |
| + data retrieval speed | + handles big data |
---
## Examples of queries for SQL and NoSQL databases :anguished:

---
This question is the source of a number of jokes, including:

---
- The truth is that NoSQL is NOT a standard. It does NOT have a specification. Of any kind.
- All it is is a term that describes a whole bunch of completely-different products.
---
In reality, you have a number of ways to query NoSQL databases, including:
- Ironically, some NoSQL databases now support SQL for querying;
- Most NoSQL databases have unique custom interfaces(eg: MongoDB)
- Many NoSQL databases support (or have plug-ins to e.g. Hadoop that support) Map/Reduce style "querying".
---
## That being said, here are some examples for queries
---
### Selecting everything from a collection:
- SQL
```SELECT * FROM userdetails;```
- NoSQL(MongoDB)
```db.userdetails.find();```
---
### Selecting with a condition
- SQL
```SELECT * FROM userdetails WHERE name = "importantperson"```
- MongoDB
```db.userdetails.find({name:"importantperson"})```
---
## But switch to anything other than MongoDB and you have new syntax
## (NoSQL is a concept, not a product/language):angry:
---
