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

Chapter 1 SQL 2024

The document discusses the importance of databases as essential assets for companies, emphasizing the value of data and its role in various applications. It explains the differences between data and information, the evolution of databases, and the types of databases, including relational and non-relational. Additionally, it outlines the database development life cycle and introduces SQL as the standard language for managing relational databases.

Uploaded by

afrazpathanst
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Chapter 1 SQL 2024

The document discusses the importance of databases as essential assets for companies, emphasizing the value of data and its role in various applications. It explains the differences between data and information, the evolution of databases, and the types of databases, including relational and non-relational. Additionally, it outlines the database development life cycle and introduces SQL as the standard language for managing relational databases.

Uploaded by

afrazpathanst
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Chapter 1:

Introduction
Why Study
Database as a Topic?
A company's database is its biggest
asset

Database processing is the heart of all


applications today
Data
It's important to understand what is
stored in a database and what can be
retrieved from it

So, if we are going to create a database,


what is going into the database?
Data
• In today's digital world, data is more
valuable than ever before
• Data is key to the smooth functioning
of everything from governments to
local companies
• The success of a company vastly
depends on how well they utilize their
data
Data
• Data can be anything and everything
• Any information or fact can be considered as data
• Examples:
▪ Personal information (name, age, date of birth, house address),
▪ Financial data (bank balance)
▪ Possessions (the vehicle you drive)
▪ Habits (the food that you eat)
▪ School or company information (teachers, students, subjects)
▪ Technology, statistics, or mathematics

• Data can be in various forms: Images, Videos, Files, Plain text


"data" and "information" are often used to mean the
same thing
However, they have different meanings in database
terminology:
What are data?
Data vs. Unorganized or unprocessed raw facts
Information What is Information?
Data with special meaning
The result of sorting, combining, comparing,
analyzing or performing calculations on data (raw
facts)
Data versus Information
Data versus Information
Is your student number data or information?
When is it data?
When is it information?

Is your grade in this course data or information?


When is it data?
When is it information?
Data
(1) Students test scores
(2) Weekly sales for each salesperson
Data vs. (3) Inventory count for each product at each
warehouse
Information Information
Examples (1) Class average
(2) Bonus as a percent of sales for the week
(3) The total company inventory for each product
Data vs.
Information
Data: Each student's exam score is
one piece of data
Information: The class average for
the exam is individual pieces or
data transformed into information
What is a Database?
• A container filled with data or information

• Electronically stored in a computer system

• Purpose:
• Easy access to data
• Modification of stored information Database
• Protection of sensitive data
• Analysis of large datasets

• Used in everyday applications:


• Google (search results)
• Instagram (posts, user profiles)
• WhatsApp (messages, contacts)
• Facebook (friend lists, posts, likes)
Database in Action
Scenario: College timesheet web application

• Features:
• Login through a URL
• Enter staff details
• Record timesheet details Data
• Track student attendance
• Store student marks Data
• Database role:
• Installed on your personal computer
• Connects to the timesheet application
• Stores all entered data
• Retrieves data when requested
• Allows modification of stored information
•Examples of DBMS:
•MySQL
•PostgreSQL
•MongoDB
•Neo4j
Database vs. DBMS
•Cassandra

• Database:
• Container that stores data app
• The actual collection of information

• DBMS (Database Management System):


• Software used to manage databases
• Allows interaction with the database DBMS user
• Used to store, modify, retrieve, and protect
data
• Can create, modify, and delete databases
• Users enter commands in a specific app
language to interact with the database
Database Management System (DBMS)
What is a Database Management System (DBMS)?

A collection of software programs that control the storage, organization, and retrieval
of data in a database

Gives us the ability to access and manipulate data without knowledge of the structure
of the database
Evolution of Databases
• 1960s: Flat file databases
• Data stored in simple files (CSV, fixed-length files)

• Hierarchical and Network databases


• Stored data through parent-child relationships
• Incapable of storing complex data relationships

• Relational databases
• Replaced earlier models due to better handling of complex
relationships

• Non-relational databases
• Emerged to handle new types of data and scale
requirements
Types of Databases Today
• Two main types:
• Relational Databases (74% usage)
• Non-Relational Databases
• Relational databases still dominate, but non-relational databases are
rising
• Reasons for non-relational database popularity:
• Immense rise in data usage over the past decade
• Growth of social media platforms
• Large companies often use a combination of both types
• Helps manage data related to millions of users daily
• Most popular examples:
• Relational: Oracle
• Non-relational: MongoDB
Relational Database
• Data stored in tables with columns and rows
• Tables are related to one another
• Structure:
• Columns have names and data types
• Rows are treated as records
• Data type acts as a rule for what can be inserted in a column
• Uses SQL (Structured Query Language) for querying
• SQL follows a standard format across different relational databases
• Examples:
• Oracle
• MySQL
• Microsoft SQL Server
• PostgreSQL: Widely used in financial institutions (banks, insurance
companies)
Relational Database
• Example: Office database
• Tables are related through common columns:
• Employee and Manager tables linked by Manager
ID
• Manager and Department tables linked by
Department ID
• Foreign key constraints form relationships between
tables
• Allows fetching data across tables based on
relationships
• Even indirectly related tables (e.g., Employee and
Department) can be queried together
What is a Relational Database?

An organized collection of related tables containing


data that can be manipulated and tables joined to
Relational provide information to users
Database Provides facilities for:
Retrieving, adding, modifying, and deleting data
Transforming retrieved data into meaningful
information
Non-Relational Database
• Categories:
• Key-Value Store
• Document Database
• Graph Database
• Wide Column Database
• Search Engine Database
• Time Series Database

• Each category stores data differently

• Designed for managing specific types of data

• Offer flexibility and scalability for certain use cases


Relational vs. non-relational databases
• The main difference between relational and non-relational
databases is how data is stored and organized.

• Non-relational databases do not store data in a rule-


based, tabular way.

• Instead, they store data as individual, unconnected files


and can be used for complex, unstructured data types,
such as documents or rich media files.

• Unlike relational databases, NoSQL databases follow a


flexible data model, making them ideal for storing data
that changes frequently or for applications that handle
diverse types of data.
Benefits of Relational Databases
• Relational databases provide an intuitive way to represent and access structured data, making them ideal for
managing large amounts of information in various applications.

• Flexibility: Easy to modify structure without impacting existing applications

• Ensures data validity and consistency

• Ease of Use: SQL queries accessible to non-technical users

• Collaboration: Supports simultaneous access with built-in locking

• Built-in Security: Role-based access control for data protection

• Database Normalization: Reduces redundancy and improves data integrity


Relational Databases

The focus of this course will be on understanding and managing


relational databases
Database Development
1. Database Planning
Life Cycle (DDLC)
Requirements Analysis
Database Design
Database Build
Database Testing
Database Deployment
Database Maintenance
Starts when a customer (user)
submits a request for the
development of a database
Step 1:
Database
Planning Four major activities are performed:
Review and Assign
Prioritize the Allocate resources
approve the development team
database project such as money,
database project to develop the
request people, and tools
request database project
Also known as the systems analysis phase

Step 2: Includes investigation and analysis of the


request

Requirements
Analysis Results in a set of requirements that the
database must support

What data is to be stored


What are the relationships
Includes: between the data
What processes are involved
Business rules
Process of creating a detailed data model
of the proposed database

Step 3:
Database
Design Three common phases in database
modeling:
Entity
Relational Data
Relationship Normalization
Model
Diagram (ERD)
Entity
Relationship
Diagram (ERD)

Graphical representation of
the proposed database
Stays the same regardless of
what type of DBMS the system
is eventually built with
Answers the questions:
What entities (person, place, or thing) are being
represented?
Entity What attributes (data) are stored about each
Relationship entity?
What are the relationships between the entities?
Diagram Basically, what data do we want to capture and what
(ERD) are the business rules surrounding that data
Example
ERD
A technique used during database design to identify
redundancy within the database

Normalization Objective is to correct un-normalized relations (tables


that contain repeating groups) using a process of
normal forms
Chapter 5
A data model expressed in terms of a relational
database structure (DB2, Oracle, MS SQL
Server, MySQL, and others)

The ER data model is transformed into a


relational data model based on the DBMS
Relational Data
being used for implementation Modeling

The transformation of the ER diagram


representing entities, attributes, and
relationships into a relational data model
representing tables, columns, an relationships
Create the database
SQL Data Definition Language (DDL) statements
Step 4: For the selected DBMS according to the requirements
Database specified in the physical data model
DBMS specific – DB2 is used in this course
Build Implement integrity constraints from business rules
Step 5: Test all constraints
Database Verify that all requirements have been met

Testing
Step 6: Allocate storage requirements
Database Place the database into production
Deployment
Database Maintenance
Step 7: Maintain the database on an on-going basis
according to user requirements
Database
Maintenance
SQL pronounced "S-Q-L" stands for Structured Query
Introduction Language

to SQL The industry-standard language of relational


database management systems (RDBMS) for
Statements manipulating and querying data in a relational
database
SQL commands are categorized into four categories:
SQL DDL (Data Definition Language)
DML (Data Manipulation Language)
Statements DCL (Data Control Language)
TCL (Transaction Control Language)
SQL commands used to create and modify the
structure of database objects:
CREATE – create the database or its objects (table,
index, function, views, store procedure and
DDL (Data triggers)
Definition DROP – delete objects from the database
ALTER – alter the structure of the database
Language) TRUNCATE – remove all rows (records) from a table
COMMENT – add comments to the data dictionary
RENAME – Rename an object existing in the
database
SQL commands that deal with the manipulation of
data in a database:
DML (Data SELECT – retrieve data from the a database
Manipulation INSERT – insert data into a table
UPDATE – update existing data within a table
Language) DELETE – delete rows (records) from a database
table
NULL Value

Some data stored in a


database can contain a What is a NULL value?
NULL value
NULL means missing, unknown, or unassigned
It is not zero (numeric) or space (alphanumeric) – it is
NULL
Consider a Customer table:
Missing – Perhaps a customer, such as Sally, does
not divulge her age to the customer service
representative
NULL Value Unknown – An employee’s termination date is
usually some event in the unforeseen future
Unassigned (doesn't apply) – If the customer is a
business, then Gender does not apply and thus is
unassigned
Data that can be NULL, is optional data
SQL commands that deal with the rights,
DCL (Data permissions, and other controls of the database
system:
Control GRANT – gives user’s access privileges to database
Language) REVOKE – withdraw user’s access privileges given
by using the GRANT command
SQL commands that deal with the transactions within
the database:
TCL COMMIT– commits a transaction
(Transaction ROLLBACK – rollbacks or reverses a transaction
when errors occur
Control SAVEPOINT – sets a SAVEPOINT within a
transaction
Language) SET TRANSACTION – specifies characteristics for
a transaction
A schema must be created before the creation of
tables and other SQL objects
A schema is an object that serves as a container for
Creating a database objects, such as tables, views, indexes,
stored procedures, and other object types
Schema A schema is created by entering the CREATE
SCHEMA command, followed by the name of the
schema, followed by a semicolon
CREATE SCHEMA myschema;
SUMMARY

You might also like