Introduction to Databases and SQL for beginners

What is data?

Data is the collection of facts like numbers, text, images, videos, etc.

The biggest example, the blog post you are reading now is a collection of text stored in a text document (but with the file extension ' .html ')

What is a database?

A database is a collection of data, but in a structured manner, which helps us to access the data very fast. There are several types of databases in this world.

But the one with which we are very familiar from our school days are text-based databases. Where the data is stored in a text document with some separators like CSV, Excel files, etc.

And the others types of databases used are Relational databases and Non-relational databases. These databases are used for large-scale applications because they are robust and suitable for big-scale applications.

What is DBMS(Database management system)?

DBMS is software that allows us to manage our Database. Our databases are just organized structured data, but to perform operations (like create, insert, delete, and update) on these databases we need DBMS software like

  • Microsoft SQL Server
  • MySQL
  • Oracle
  • SQLite
  • MongoDB
  • PostgreSQL

There are mainly two types of database management systems:

  • Relational database management system (RDBMS) eg: Microsoft SQL Server, MYSQL, PostgreSQL
  • Non-relational database management system (No-SQL) eg: MongoDB , Redis

Relational Databases:

In this tech world, all relational databases are using tables to store data. And we are using this data representation in RDBMS for 50 years.

So when you are working with relational databases and when you hear the term data, you should think of tables.

So in relational databases, data is stored in tables.

Here's what a table looks like in a database.

Table table in a relational database.PNG

Table in a relational database

Fields:

id, first_name, and last_name in the below table are called fields. In a nutshell, columns are called fields in a table. table in a relational database 2.PNG

Records: A record is a group of data that describes the characteristics of the entity.

But what is an entity? The entity is a real-world object like a car, books, etc. Here in the table, we are referring to a Person as our entity.

In a nutshell, records are rows of the table. Every single row is called a record. table in a relational database 3.PNG

But why there is a term called relation in the relational databases?

Well, tables in a relational database are related one to another with a common field or column. And it is also called a foreign key.

primary key: A primary key is a value that uniquely identifies a record in a table. such as an "id" column in the below table.

table in a relational database 3.PNG

Here all "id" values should be unique, that's when the "id" column can be called a primary key.

Non-Relational Databases or NoSQL Databases:

These databases don't store data in tables, instead, they store data in several ways like in key-value pairs, JSON documents, or graphs.

NoSQL databases are very new, and they are invented for applications that run trillions and billions of query requests per second.

To handle such a huge number of queries, traditional RDBMS is very expensive because we need to store relationships with data. like so we also need to check the relationships between the tables to serve data for users which is very time-consuming and also needs strong computational power.

NoSQL databases are used for projects which need billions and trillions of query requests.

What is SQL?

SQL is a structured query language that is used to talk with our databases.

We can tell our database to show some data, delete some data, add some data and also update data. Not just this we can manage the whole database with SQL.

Few lines of SQL code or just a line of SQL code that performs a task is called a Query.

Example of SQL query to retrieve a table from the IMDB database:

sql query example.PNG

Read my other blogs to understand more about SQL in detail.