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

Lecture 9

This document provides an overview of databases and SQL. It begins with defining what a database is and discussing different data models like hierarchical, network, relational, and object-oriented models. It then explains what a database management system (DBMS) is and some basic database terminology. It also covers SQL, the structured query language used to manage data in databases, and provides some examples of SQL statements for data retrieval, insertion, deletion and updating.

Uploaded by

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

Lecture 9

This document provides an overview of databases and SQL. It begins with defining what a database is and discussing different data models like hierarchical, network, relational, and object-oriented models. It then explains what a database management system (DBMS) is and some basic database terminology. It also covers SQL, the structured query language used to manage data in databases, and provides some examples of SQL statements for data retrieval, insertion, deletion and updating.

Uploaded by

Aliya Mukhtarova
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

DATABASES AND SQL

Lecture №9
Lecture’s Outline
The aim of topic: learn how to work with big data or database, explore the database,
can create the table using SQL.

Agenda:
 Database
 Data Models
 Database Management System
 Basic terminology in Databases
 Database Management Applications
 Structured Query Language
Database
A database is a structured collection of records or data. A computer database is a kind of software to
organize the storage of data. Databases help you organize this related information in a logical
fashion for easy access and retrieval. To develop a database, there are several models used such as
Hierarchical model, Network model, Relational model, Object-Oriented model etc. Though
discussing about these models in details is beyond the level of this course unit, for the sake of
completion, some models are briefed below.
Data models

Hierarchical model. In a hierarchical model, data is organized into an inverted tree-like


structure. This structure arranges the various data elements in a hierarchy and helps to
establish logical relationships among data elements of multiple files. Each unit in the
model is a record which is also known as a node. Each record has a single parent.
Data models

Network model. The network model tends to store records with links to other records. Each record
in the database can have multiple parents, i.e., the relationships among data elements can have a
many to many relationships. So this model is an expansion to the hierarchical structure, allowing
many-to-many relationships in a tree-like structure that allows multiple parents.

The network model provides greater advantage than the hierarchical model in that it promotes
greater flexibility and data accessibility.
Data models

Relational model. The relational model for the database management is a database model based on
relations. The basic data structure of the relational model is a table where information about a
particular entity (say, a student) is represented in columns and rows. The columns enumerate the
various attributes (i.e. characteristics) of an entity (e.g. student name, address, registration number).
The rows (also called records) represent instances of an entity (e.g. specific student).
Data models

Object–Oriented model. It provides full-featured database programming capability, while


containing native language compatibility. It adds the database functionality to object programming
languages. This approach is the analogical of the application and database development into a
constant data model and language environment. Applications require less code, use more natural data
modeling, and code bases are easier to maintain. Object developers can write complete database
applications with a decent amount of additional effort. But object-oriented databases are more
expensive to develop.
Database Management System

A Database Management System (DBMS) is computer housekeeping tasks such as updating data,
deleting obsolete records, and backing up the database.

Obtaining subsets of data software designed for the purpose of managing databases based on a variety
of data models. A DBMS is a complex set of software programs that controls the organization,
storage, management, and retrieval of data in a database. DBMS are categorized according to their
data structures or types, sometime DBMS is also known as a Database Manager. Data management
tasks fall into one of four general categories as given below:
● Entering data into the database.
● There are several advantages in DBMS such as reduced data redundancy and inconsistency,
enhanced data integrity, improved security etc.
Database Management System

Database Table
Object

Relationships DBMS Foreign Key

Field
Record Primary Key
Basic terminology in Databases

Database. A database is an organized collection of the related information


Basic terminology in Databases
Object. An object is a component in the database such
as a table, query, form, report, or macro, etc.
Basic terminology in Databases
Table. A table is a group of related data organized in fields (columns) and records (rows)
on a datasheet. By using a common field in two tables, the data can be combined. Many
tables can be stored in a single database
Basic terminology in Databases
Field. A field is a column on a datasheet and defines a data type for a set of values in a table. For a
mailing list table might include fields for first name, last name, address, city, and telephone number.
Basic terminology in Databases
Record. A record is a row on a datasheet and do fields define a set of values. In a mailing list table,
each record would contain the data for one person as specified by the intersecting fields.
Basic terminology in Databases
Primary key. A primary key is used to uniquely identify each row in a table. It can
either be a part of the actual record itself, or it can be an artificial field (one that has
nothing to do with the actual record). A primary key can consist of one or more fields
on a table. When multiple fields are used as a primary key, they are called as a
composite key.
Basic terminology in Databases
Foreign key. A foreign key is a field (or fields) that points to the primary key of another
table. The purpose of the foreign key is to ensure referential integrity of the data.
Basic terminology in Databases
Relationships. Two tables/entities in a database may relate to each other using one or
more common attribute. There are three types of relationships among tables namely, One-
to-one, one-to-many, many-to-many.
External, conceptual, and internal views
A database management system provides three views of the database data:

The external level defines how each group of end-users sees the organization of data in
the database. A single database can have any number of views at the external level.

The conceptual level unifies the various external views into a compatible global view.
It provides the synthesis of all the external views. It is out of the scope of the various
database end-users, and is rather of interest to database application developers and
database administrators.

The internal level (or physical level) is the internal organization of data inside a
DBMS. It is concerned with cost, performance, scalability and other operational
matters. It deals with storage layout of the data, using storage structures such as indexes
to enhance performance.
Languages

Database languages are special-purpose languages, which do one or more of the


following:
 Data definition language – defines data types such as creating, altering, or dropping
and the relationships among them
 Data manipulation language – performs tasks such as inserting, updating, or deleting
data occurrences
 Query language – allows searching for information and computing derived
information.
Database Management Applications
There are several different database management applications which are not only meant
for entering and retrieving information but also they facilitate simultaneous updates and
queries from multiple users.

Some of the database management applications are listed below:


Database structure

Databases are designed to offer an organized mechanism for storing, managing and
retrieving information.
Server stores many databases
Database stores tables
Tables are constructed by fields
Table saves each data in a row
Fields have type. e.g. integer, string, date, datetime, boolean
Tables: example

Database is MySDU
Tables are students, course, teachers
Fields are name (string/varchar), surname (string/varchar), age (integer)
SQL

SQL - structured query language


SQL is special language to retrieve, update, delete data from database
How does it work:
we write SQL request in code that sends it to SQL server and then retrieve response
SQL
SQL data retrieving: example

fields to output, put *


SELECT name,surname to output all fields
FROM contacts table that is retrieved
WHERE name='John'
ORDER BY surname Filtering results by
setting conditions
Output result sorted by
specified field
SQL
SQL insert, delete, update:

INSERT INTO students (name,surname) values (‘Berik’,’Sakenov’)


DELETE FROM students WHERE name = ‘Berik’
UPDATE students SET name=’Serik’ WHERE name=’Berik’

SQL aggregate functions:


SELECT COUNT(*) FROM users
SELECT MIN(age) FROM users
SELECT AVG(age) FROM users
SELECT DISTINCT(surname) FROM users
Thank you for your attention!

You might also like