0% found this document useful (0 votes)
2 views

Learn SQL - Day 1 of 10DaysOfSQL

This document is a guide to understanding SQL and databases, covering the basics of what a database is and how it is managed through a Database Management System (DBMS). It explains the differences between relational (SQL) and non-relational (NoSQL) databases, the functionalities of a good DBMS, and the types of SQL commands used for database operations. The guide also highlights the importance of data types and how data is physically stored in SQL databases.

Uploaded by

reka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Learn SQL - Day 1 of 10DaysOfSQL

This document is a guide to understanding SQL and databases, covering the basics of what a database is and how it is managed through a Database Management System (DBMS). It explains the differences between relational (SQL) and non-relational (NoSQL) databases, the functionalities of a good DBMS, and the types of SQL commands used for database operations. The guide also highlights the importance of data types and how data is physically stored in SQL databases.

Uploaded by

reka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

A quick guide on

Understanding SQL
Day 1 of #10DaysOfSQL

@talhakhan 1
But first, you need to
understand

THE BASICS
Let’s start with databases

@talhakhan 2
A database is a collection
of RELATED information

ANY collection of related information


▪ Phonebook
▪ Shopping List
▪ To do list
▪ LinkedIn User Base
▪ Your 5 favorite food

Database can be stored in different ways


▪ On Paper
▪ This PowerPoint
▪ Comments section
▪ On a computer
▪ Ledgers

@talhakhan 3
Databases can be very large, and
databases touch all aspects of our
lives

Banking: transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Online retailers: order tracking, customized
recommendations
Manufacturing: production, inventory, orders,
supply chain
Human resources: employee records, salaries,
tax deductions

@talhakhan 4
DBMS is Database
Management System (DUH!)

A Database Management System is a


software system that allows access to data
contained in a database.
It is not an actual database

The objective of the DBMS is to provide a


convenient and effective method of
defining, storing, and retrieving the
information contained in the database.
• Makes it easy to manage large amounts of
information
• Handles security
• Backup
• Access management
• Import/Export data

@talhakhan 5
CREATE. READ. UPDATE.
DELETE

• A good DBMS should have all these


functionalities:
• The ability to create records / columns
• The ability to read what’s already there in
the database
• The ability to update the existing
information
• The ability to delete existing information

@talhakhan 6
Relational Databases (SQL) and
Non-Relational Databases
(NoSQL)

Relational Databases (SQL)


• Data is stored in one or more tables
• Each table has columns and a row
• A unique key identifies each row

Non-Relational Databases (NoSQL)


• Data is not stored in tables
• It can be stored in:
• Key-value stores
• Documents (JSON, XML etc.)
• Graphs

@talhakhan 7
A relational database stores and
organizes data into tables linked
together based on common
columns.

What is the relation here? What is common


between both the tables?

Yes, it’s Department ID. That’s the ‘relation.’


Employees Table
EmployeeID Name DepartmentID
1 John 1
2 Sara 2
3 Bob 3
4 Charlie 4
5 Alice NULL

Department Table
DepartmentID DepartmentName
1 HR
2 Sales
3 IT
6 Finance

@talhakhan 8
Relational Database
Management System
(RDBMS)

Used to create and maintain a relational


database

Some examples of RDBMS and vendors:

▪ MySQL
▪ Oracle
▪ PostgreSQL
▪ Microsoft SQL Server (MSS)

@talhakhan 9
SQL (structured query
language) is a standardized
language for interacting with
RDBMS

But what is a Query?


• A Google search is a query
• Query are requests made to the DBMS for specific
information
• As a database’s structure becomes more
complex, it becomes more difficult to get the
specific pieces of information we want.

SQL is used to:


• Perform C.R.U.D operations, as well as other
administrative tasks such as security, backup and
access management
• Create and manage databases
• Design and create database tables
• SQL code (syntax) used on one RDMBS is not
always directly portable to another RDBMS without
modifications – slight@talhakhan
changes are required 10
A hybrid language with 4
different types of language
combined into one

1. DQL
• Data Query Language
• Used to query (request) the database for
information
• Get information that is already there
• SELECT Statements

2. DDL
• Data Definition Language
• Used for defining database schemas
• CREATE, ALTER, DROP, TRUNCATE,
RENAME

@talhakhan 11
A hybrid language with 4
different types of language
combined into one

3. DCL
• Data Control Language
• Used for controlling access to the data in
the database
• User access and permission management
• GRANT, REVOKE

4. DML
• Data Manipulation Language
• Used for inserting, updating, and deleting
data from the database
• INSERT, DELETE, UPDATE

@talhakhan 12
A data type specifies the
kind of data that can be
stored in a column

Some examples:
• INT – Whole Numbers
• DECIMAL(M,N) / FLOAT – Decimal Numbers
• VARCHAR(32) – String of text of length 32
• BLOB – Binary Large Objects, Stores large
data
• DATE – ‘YYYY-MM-DD’
• TIMESTAMP – ‘YYYY’MM’DD HH:MM:SS’
used for recording different events,
transactions, continuous values etc.

@talhakhan 13
Data is logically stored in rows
and columns in a table – but
where is it physically stored?

In SQL databases, data is physically stored in


fixed-size storage units called data pages,
often a few kilobytes.

These pages are organized in a file system


managed by the database system.

There are typically two main types of data


pages:

Data Pages (lead nodes): These contain the


actual data of the tables, like the rows and
columns of information (data).

Index Pages (root and intermediate nodes):


These are used to speed up searches; they
store index information that points to the
@talhakhan 14
actual data pages.
• Database is any collection of related
information
• Computers are great for storing
databases
• Database Management System (DBMS)
makes it easy to create, maintain, and
secure a database
• DBMS allow you to perform C.R.U.D.
operations and other administrative
tasks
• Two types of Databases: Relational vs
Non-Relational
• Relation Databases use RDBMS, and
RDBMS use SQL to store data in tables
with rows and columns
• Non-Relational data is stored using
other data structures like JSON, graphs,
key-value stores etc.
• SQL data is physically stored in storage
units called Data@talhakhan
Pages 15
In next episode, we will
discuss:

Basic SQL Queries with Examples


Order of Query Execution
Best practices

Stay tuned

@talhakhan 16

You might also like