Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created May 12, 2022 11:21
Show Gist options
  • Save halitbatur/94643c7ab95b676ff44eeb4375079ff6 to your computer and use it in GitHub Desktop.
Save halitbatur/94643c7ab95b676ff44eeb4375079ff6 to your computer and use it in GitHub Desktop.
Discussion about SQL vs noSQL

Discuss the answers for these questions with you teammates and write your answers in the comments.

  1. What is the difference between SQL and NoSQL?
  2. What is referencing and what is embedding in MongoDB?
  3. Why should we embed more than referencing when we can in MongoDB?
  4. When should we prefer referencing over nesting in MongoDB?
  5. What are ORMs? Why we use them? Give an example of an SQL request with and without using ORM.
  6. What is the difference between a table and a collection?

Some helpful resources:

@khaldarov
Copy link

Huzeyfe Abdullahoglu, Emine Cig, Sara Hamoud, Adnan Khaldar

1.What is the difference between SQL and NoSQL?

SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores. Some examples of SQL databases include MySQL, Oracle, PostgreSQL, and Microsoft SQL Server. NoSQL database examples include MongoDB, BigTable, Redis, RavenDB Cassandra, HBase, Neo4j, and CouchDB.
SQL databases are relational, NoSQL databases are non-relational.
SQL databases use structured query language and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data.
SQL databases are vertically scalable, while NoSQL databases are horizontally scalable.
SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores.
SQL databases are better for multi-row transactions, while NoSQL is better for unstructured data like documents or JSON

  1. What is referencing, and what is embedding in MongoDB?
    Embedding can be explained by the idea that one embeds data inside each other.
    Referencing can be explained by one arranging 2 or more data sets separately, but connect them with key data that is called a “reference.” Thus, they could be separate yet connected.

3.Why should we embed more than referencing when we can in MongoDB?

it’s faster than referencing, we can read and update data in a single operation

4.When should we prefer referencing over nesting in MongoDB?

We can think of an example: having a biiig box that has everything about our computer. Finding a battery for our mouse inside that big box would be like hell! But when we have smaller boxes, all labeled “computer components,” and some other info, we could easily find everything we need, in seconds.

5.What are ORMs? Why we use them? Give an example of an SQL request with and without
using ORM.

ORMs -Object Relational Mappings- are simply libraries that make it easier to communicate with the databases.

6.What is the difference between a table and a collection?

Instead of tables, a MongoDB database stores its data in collections. A collection holds one or more BSON documents. Documents are analogous to records or rows in a relational database table. Each document has one or more fields; fields are similar to the columns in a relational database table

@halakhellow
Copy link

@cbaksakal
Copy link

1. What is the difference between SQL and NoSQL?

  • SQL databases are relational, NoSQL databases are non-relational.
  • SQL databases use structured query language and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data.
  • SQL databases are vertically scalable, while NoSQL databases are horizontally scalable.
  • SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores.
  • SQL databases are better for multi-row transactions, while NoSQL is better for unstructured data like documents or JSON.
  • NoSQL: MongoDB, Cassandra / SQL: MySQL, PostgreSQL

2. What is referencing and what is embedding in MongoDB?
Referencing means that the documents in a collection will be held separately. Therefore, the child document is going to have a reference to the parent document.

In embedding, parent document includes child documents in a nested manner. There will be no need to give a reference to the parent document.

3. Why should we embed more than referencing when we can in MongoDB?
Embedding is faster than referencing because we can read and update data in a single operation up to 16 mb. It is easier to use.
Generally used for one-to-many relations. "Has a", "contains" relation.

4. When should we prefer referencing over nesting in MongoDB?
If we have large files, a lot of child documents and we need fine control, we might use referencing. Referencing is also advantageous when we have many-to-many relationships.

5. What are ORMs? Why we use them? Give an example of an SQL request with and without using ORM.
ORMs -Object Relational Mappings- are simply libraries that make it easier to communicate with the databases. Normally, we are supposed to write full SQL queries as strings to communicate with the database. However, these SQL queries are time consuming and error-prone; even one typo would make our query fail. At that point, ORMs come to the rescue. Instead of typing queries by hand as a string, we use the commands of related language which behind the scenes uses SQL to communicate with the database.

6. What is the difference between a table and a collection?
Tables are used in SQL. Each row in a table has the same number of columns.

Collections are used in NoSQL. They are similar to the tables in SQL; however, each document in a collection can have a different number of columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment