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:

@yamanrajab90
Copy link

yamanrajab90 commented May 17, 2022

Team Members are :
Yaman ,Mohammad ibrahim ,Hamza

1: What is the difference between SQL and NoSQL

-SQL: relational, use structured query language and have a predefined schema, is vertically scalable, is table-based.
-NoSQL: non-relational, NoSQL databases have dynamic schemas for Unstructured data, are horizontally scalable, and are document, key-value, graph, or wide-column stores.

2: What is referencing and what is embedding in MongoDB?
References are one way NoSQL databases handle one-to-many relationships. In relational databases, referencing is more comparable to associations than embedding. Foreign keys are used in references, but the point from one document to another, rather than from one table to another.
Document embedding is another way NoSQL databases manage this type of one-to-many interaction. When one document is embedded within another, the result is a big hash. The author document, for example, would contain numerous post documents, and each posted document would contain many comment documents. Each author document is a hash that contains an array of posts, each of which contains an array of comments.

3: Why should we embed more than referencing when we can in MongoDB?
Both embedding and referring are viable solutions, but each serves a different purpose. Before making a decision, there are a few factors to consider. Data consistency and document size, Embedding documents lead to better performance because we can read and update data in a single database operation,

4:When should we prefer referencing over nesting in MongoDB?
In general,, reference is better for many-to-many relationships.

5: What are ORMs? Why do we use them? Give an example of an SQL request with and without using ORM.
Object-relational mapping (ORM) is a programming technique in which a metadata descriptor is used to connect object code to a relational database. Object code is written in object-oriented programs (OOP) languages such as Java or C#

why should we use it?

  1. we get to write in the language we are already using anyway. taking leverage of the fluency is awesome!
  2. It has many advanced features out of the box, such as support for transactions, connection pooling, migrations, seeds, streams, and all sorts of other goodies.
  3. Many of the queries you write will perform better than if you wrote them yourself.

an example of an SQL request without using ORM :
SELECT * FROM users WHERE email = '[email protected]';
and with using ORM:

var orm = require('generic-orm-libarry'); var user = orm("users").where({ email: '[email protected]' });

6: What is the difference between a table and a collection?
6- In an SQL database we store our data in column and row (a record) and what hold those rows and column is called tables each database can have multiple tables, in the case of a NoSQL database like MongoDB we have a collection instead of table and inside each table, we can have multiple documents in a collection and inside the documents, we have multiple fields instead of columns.

@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