0% found this document useful (0 votes)
11 views30 pages

Topic 4: Introduction To Database Management Systems

Uploaded by

viksithv
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)
11 views30 pages

Topic 4: Introduction To Database Management Systems

Uploaded by

viksithv
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/ 30

TOPIC 4: INTRODUCTION TO DATABASE

MANAGEMENT SYSTEMS
Fundamentals of ICT – ETC 2191 R Vasana Sahabandu
TOPIC 4: CONTENT

WORKING WITH DBMS BASIC SQL COMMANDS


The programmer had to handle all details of data storage and
retrieval
BEFORE  Low level programming
DATABASE  A new wheel invented all the time
MANAGEMENT  All data in flat files with different format
SYSTEMS  Hard to maintain data integrity
 Hard to handle simultaneous data access
A system for storing
A system for
data in a
retrieving data easily
standardized manner

WHAT IS A DATABASE
A system for MANAGEMENT
protecting data A tool for simplifying
against failure and system development SYSTEM (DBMS)?
unauthorized access

Relieves the
programmer of
physical data storage
DIFFERENT TYPES OF DBMS

 Hierarchical DBMS, 60s


 Relation DBMS, RDBMS, 70s
 Object DBMS, 80s
 Object-relational DBMS, 90s
 Most databases today are RDBMS or Object-relational DBMS
 NoSQL.
RELATIONAL DATABASE SYSTEMS

 Started in the 70s at IBM by Codd


 Several implementations by companies like Oracle, Sybase,
Upright and Microsoft
 Highly optimized systems
 Proven and mature technology
 Several international standards
 Most systems today uses a RDBMS
THE RELATIONAL MODEL

All data is stored in tables with rows and columns

PERSON

PID FName LName Sex Age

1 Nimal Bandara Male 25

2 Kamala Silva Female 50


THE RELATIONAL MODEL

Relationships between tables

Person_Cars Person

PID car PID Name ………


1 Volvo 1 Nimal ………
2 Kamala ………
DATA LAKES & DATA WAREHOUSES

 Data lakes and data warehouses are storage systems for big data used by data
scientists, data engineers, and business analysts. Despite their similarities,
though, they're more different than they are similar, and understanding these key
differences is important for any aspiring data professional.
 Data lakes, much like real lakes, have multiple sources ("rivers")
of structured and unstructured data that flow into one combined site. Data
warehouses are designed to be repositories for already structured data to be
queried and analyzed for very specific purposes.
 For some companies, a data lake works best, especially those that benefit from
raw data for machine learning. For others, a data warehouse is a much better fit
because their business analysts need to decipher analytics in a structured system.
THE KEY DIFFERENCES

Parameters Data Lake Data Warehouse


Processed (data stored according to metrics
Data type Raw (all types, no matter source of structure)
and attributes)
Data purpose To be determined Currently being used
Process Extract Load Transform (ELT) Extract Transform Load (ETL)
Schema After data storage, to offer agility and easy Before data storage, to offer security and high
position data capture performance
Data scientists, those who need in-depth
Business professionals, those who need it for
Users analysis and tools (such as predictive
operations
modeling) to understand it
Accessibility Accessible and easy to update Complicated to make changes
History Relatively new for big data The concept has been around for decades
QUERY LANGUAGES

 No standardized languages in the beginning


 One query in Oracle would not work in Mimer
 Hard for the developer to know many languages
 No portability
 Locked into one vendor
STRUCTURED QUERY LANGUAGE (SQL)

 SQL is an ISO standard supported by basically all vendors, more


or less
 SQL 92, SQL 99 and the new SQL 200x
 SQL is used to create the data model
 SQL is used to query the database
 SQL is used to perform updates
 Powerful language created to manipulate data
Table name Attribute
names

Product
PID PName Price Category Manufacturer
TABLES
FURTHER
1A Gizmo 19.99 Gadgets GizmoWorks
EXPLAINED
Powergiz
1B 29.99 Gadgets GizmoWorks
mo
SingleTou Photograp
1C 149.99 Canon
ch hy
MultiTouc Househol
1D 203.99 Hitachi
h d

Tuples or rows
TABLES FURTHER EXPLAINED

 The schema of a table is the table name and its attributes:


Product(PID, PName, Price, Category, Manufacturer)

 A Primary Key is an attribute whose values are unique (cannot have duplicate
values) and not NULL (must have a value). It is usually underlined.
Product(PID, PName, Price, Category, Manfacturer)

 A tuple is a record in a table (a row); a table is a set of tuples.


SQL DATA TYPES

 Data types:
 String: CHAR(20), VARCHAR(50), etc.
 Numeric: INT, BIGINT, SMALLINT, FLOAT, etc.
 Others: DATETIME, TIMESTAMP, etc.

 Every attribute must have data type


SELECT STATEMENT: RETRIEVING DATA

SELECT <attributes>
FROM <one or more tables>
WHERE <conditions>

The SELECT statement is used to retrieve data FROM a table.


SELECT * FROM Person

SELECT STATEMENT:
SELECT PID, FName FROM Person EXAMPLES

SELECT *
FROM Person
WHERE Age>25 AND Sex='Male'
SELECT STATEMENT: EXAMPLE

Product
PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
SELECT * MultiTouch $203.99 Household Hitachi
FROM Product
WHERE Category='Gadgets'

PName Price Category Manufacturer


Gizmo $19.99 Gadgets GizmoWorks

“selection” Powergizmo $29.99 Gadgets GizmoWorks


SELECT STATEMENT: EXAMPLE

Product
PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
SELECT PName, Price, Manufacturer MultiTouch $203.99 Household Hitachi
FROM Product
WHERE Price>100

PName Price Manufacturer


“selection” and SingleTouch $149.99 Canon
“projection” MultiTouch $203.99 Hitachi
LIKE OPERATOR

SELECT *
FROM Products
WHERE PName LIKE '%gizmo%'

LIKE operator is used in a WHERE clause to search for a specified pattern.


There are two wildcards used for this:
 % = any sequence of characters
 _ = any single character
INSERT STATEMENT: INSERTING DATA

INSERT INTO R(A1,…., An) VALUES (v1,…., vn)

Data is inserted with the INSERT statement INTO a table (with attributes)
with VALUES as a tuple.

INSERT INTO Purchase(buyer, seller, product, store)


VALUES ('Joe', 'Fred', 'wakeup-clock-espresso-machine’,
'The Sharper Image')
INSERT INTO Person (PID,
FName, LName, Sex, Age)
VALUES (3, 'Srimalee',
'Kumara', 'Female', '27') INSERT STATEMENT:
EXAMPLES

INSERT INTO
Person_Cars(PID, Car)
VALUES (3, 'Toyota')
UPDATE STATEMENT: UPDATING DATA

UPDATE PRODUCT
SET price = price/2
WHERE name LIKE 'J%'

Data is updated in a table using the UPDATE statement.


UPDATE Person SET
Age=22 WHERE PID=1
UPDATE
• Update age to 22 in the
STATEMENT:
record where PID is 1
EXAMPLES
UPDATE Person_Car
SET Car=' Volvo'
• Updates all cars to Volvo
DELETE STATEMENT: DELETE DATA

DELETE FROM PURCHASE


WHERE Seller = 'Joe' AND
Product = 'Brooklyn Bridge'

Tuples in a table are deleted using the DELETE statement.


DELETE STATEMENT: EXAMPLE

 DELETE FROM Person WHERE PID=3


 Deletes the row where the PID is 3.
CREATING TABLES

 Tables can be created with the create command


 CREATE TABLE Person (PID int, FName char(10), LName char(10), Sex char(6),
Age int)
 CREATE TABLE Person_Car (PID int, Car char(7))
 Primary keys are defined in the create statement
 CREATE TABLE Person (PID int, FName char(10), LName char(10), Sex char(6),
PRIMARY KEY (PID))
ALTERING A TABLE

 A table can be altered using the ALTER TABLE statement, after


it has been created
 ALTER TABLE Person DROP COLUMN Age
• Deletes the column named ‘Age’ from the table ‘Person’
 ALTER TABLE Person ADD Age int
• Adds a column named ‘Age’ with the datatype ‘int’ to the table ‘Person’
DELETING A TABLE

 The DROP TABLE statement is used to delete a table in a


database.
 DROP TABLE Person
Q &A

You might also like