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:

@HamzaAymen
Copy link

HamzaAymen commented May 17, 2022

1-
SQL databases are primarily called as Relational Databases (RDBMS); whereas NoSQL database are primarily called as non-relational or distributed database.

SQL databases defines and manipulates data based structured query language (SQL) , A NoSQL database has dynamic schema for unstructured data. Data is stored in many ways which means it can be document-oriented

In almost all situations SQL databases are vertically scalable. This means that you can increase the load on a single server by increasing things like RAM, CPU or SSD. But on the other hand NoSQL databases are horizontally scalable. This means that you handle more traffic by sharding, or adding more servers in your NoSQL database

2-
references save the _id field of one document in another document as a reference.
And embedded those types of documents which contain a document inside another document

3-
Because storing them as embedded will just needlessly increase response times due to more queries being executed than needed

4-
When your data is being referred to from multiple locations and you need to access your data from multiple locations, we should be using references

5-
(ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm and it makes it easier to communicate with a database in code

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-
In SQL database we store are data in column and row (record) and what hold those rows and column called tables and each database can have multiple tables , in case of noSql database like , MongoDb we have collection instead of table and inside each table we have can have multiple documents and inside documents we have multiple fields instead of columns.

@muhammed-shihebi-boot
Copy link

@irem-kurt
Copy link

Noor, Abdul Hafız, Ezgi, İrem

question number (1) :
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.
question number (2) :
Both are ways to handle relationships in no-SQL databases
Referencing: similar to association in relational databases, it also utlizes foriegn keys the same way, however the relation here is from one document to another rather than from a table to one record in another table in relational DB.
Embedding: another way to handle relations by embedding one document within another, resulting in what is basically a giant hash. where each embedded document contains an array of it’s attributes.

question number (3) :
​​You absolutely must store unstructured data. Say things coming from 3rd-party API you don’t control, logs whose format may change any minute, user-entered metadata, but you want indexes on a subset of it.
You need to handle more reads/writes than single server can deal with and master-slave architecture won’t work for you.
You change your schema very often on a large dataset.

question number (4) :
each has it’s unique use cases, if the data is accessed from multiple locations referencing is better, if the data needs to be related to a parent document embedding is the best to use here.

moreover embedding is good if you have one-to-one or one-to-many relationships between entities, while referencing is good if you have many-to-many relationships.

question number (5) :
ORM is a library that makes it easier to communicate with a database in code. It is basically a technique to query or perform CRUD (Create, Read, Update, Delete) operations to the database, mainly RDBMS (Relational Databases), using an object-oriented paradigm.
question number (6):
A table is made up of a fixed number of columns for any number of rows. Every row in a table has the same columns. Collection in MongoDB for example: A collection in MongoDB is made up of documents
References:
Q3-https://www.quora.com/In-Mongodb-when-should-we-use-embedding-and-when-should-we-use-referencing

@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