Lesson 02 Introduction To SQL
Lesson 02 Introduction To SQL
Learning Objectives
• Data can be in several forms, including numbers, text, and bits or bytes.
What Is a Database?
• Databases are often created using formal design and modeling approaches, and
they are typically managed using a Database Management System (DBMS).
• The data, DBMS, and associated applications are referred to as a database system
or database.
Types of Databases
Relational database
NoSQL database
Graph database
Centralized database
Distributed database
Relational Database
• A relational database is a collection of data objects that are linked together by pre-
defined relationships.
• A relational database's data is structured into tables, where the rows are records with
a unique ID in each row called the key.
• Also, the columns are data attributes, with each record generally having a value for
each attribute, making it easier to establish relationships among data points.
• NoSQL databases are nontabular databases that store data in JSON documents
instead of relational tables.
• They are classified into several categories based on their data model, such as
document, key-value, wide-column, and graph databases.
• The graph database (GDB) is a database that uses graph structures to describe and
store data for semantic queries with nodes, edges, and attributes.
• An edge contains a start node, an end node, a type, and a direction, and it may also be
used to describe parent-child relationships, actions, and ownership.
• A distributed database (DDB) is a unified collection of several linked databases that are
physically dispersed across multiple locations in a computer network.
• In order to form a distributed database system (DDBS), the files must be structured,
logically interconnected, and physically distributed over several sites.
DBMS RDBMS
• It stores data that is not related to each • Data stored in tables is related via foreign
other. keys.
• Data fetching is slower for complex and • Data fetching is rapid because of the
large volumes of data. relational approach.
DBMS vs. RDBMS
DBMS RDBMS
• Examples: File System, XML, MS Access, and • Examples: MySQL, PostgreSQL, Oracle, and
Windows Registry SQL Server
Structured Query Language (SQL)
Column
Emp_Details
Table name
Row
Tables in MySQL
• Tables are database objects with unique names which consist of a collection of data stored
in a database.
• Each table includes data points of an object which are logically structured in a row and
column format.
• A table can have any number of rows, but it must have a certain number of columns.
Description: The database contains person records (since 1900). Each person can have a mother
and/or father. Women can have one husband, and men can have one wife. Persons work in companies,
which contain a name and one chairman. One person can work for one or more companies, mandatory
contract, or an employment contract.
Relationships in MySQL
• A relationship is a condition that exists between two tables in a database when data from
one table reflects data from another table.
• Relationships enable relational databases to divide and store data in many tables while
connecting dissimilar data components.
• Two tables are required to form a table relationship at the same time, one of which is
called the primary or parent table and the other the related or child table.
Views in MySQL
• Views are virtual tables in SQL that are built by choosing fields from one or more tables
present in the database.
• Views do not contain any data and do not exist physically in the database.
• A view is a collection of preset SQL queries that are used to retrieve data from the
database.
• A view can represent all the data in a table or only specific rows based on certain criteria.
Table vs. View
Table View
• Tables are database objects that comprise • Views are virtual tables in SQL that are built
a collection of data stored in a database. by choosing fields from one or more tables
present in the database.
• Tables contains data and exist physically
in the database. • Views do not contain any data and do not
exist physically in the database.
• A table is an independent data object.
• A view depends on tables.
Key Takeaways