SlideShare a Scribd company logo
1 of 61
Database Management
Systems
Session 1
What is a DBMS?
• Collection of interrelated data – manual or
computerized or online
• Set of programs to access the data
• DBMS provides an environment that is both
convenient and efficient to use.
2
Applications Areas of DBMS?
 Banking: all transactions
 Airlines: reservations, schedules
 Universities: registration, grades
 Sales: customers, products, purchases
 Manufacturing: production, inventory, orders, supply chain
 Human resources: employee records, salaries, tax
deductions
Databases touch all aspects of our lives
3
• To avoid data redundancy and inconsistency
Multiple file formats, duplication of information in
different files
• To avoid difficulty in accessing data
Need to write a new program to carry out each
new task
• To deal with data isolation — multiple files and
formats
• To deal with integrity problems
Integrity constraints (e.g. account balance > 0)
become part of program code
Easy to add new constraints or change existing
ones
Why do we use DBMS
4
1. Atomicity of updates
• Failures may leave database in an inconsistent state with partial
updates carried out
• E.g. transfer of funds from one account to another should either
complete or not happen at all
2. Concurrent access by multiple users
• Concurrent accessed needed for performance
• Uncontrolled concurrent accesses can lead to inconsistencies
o E.g. two people reading a balance and updating it at the same
time
3. Security problems
Why do we use DBMS (contd..)
5
Relational Model
Example of tabular data in the relational model
customer-
name
customer-id
customer-
street
customer-
city
account-
number
Johnson
Smith
Johnson
Jones
Smith
192-83-7465
019-28-3746
192-83-7465
321-12-3123
019-28-3746
Alma
North
Alma
Main
North
Palo Alto
Rye
Palo Alto
Harrison
Rye
A-101
A-215
A-201
A-217
A-201
Attributes
6
A Logically Related Database
7
Database Users
Users are differentiated by the way they expect to interact with the
system
• Application programmers – interact with system through DML
calls
• Sophisticated users – form requests in a database query
language
• Specialized users – write specialized database applications that
do not fit into the traditional data processing framework
• Naïve users – invoke one of the permanent application
programs that have been written previously
 E.g. people accessing database over the web, bank tellers, clerical staff
8
Database Administrator
• Coordinates all the activities of the database
system
• Has a good understanding of the enterprise’s
information resources and needs.
• Database administrator’s responsibilities include:
 Schema definition
 Storage structure and access method definition
 Schema and physical organization modification
 Granting user authority to access the database
 Specifying integrity constraints
 Acting as liaison with users
 Monitoring performance and responding to changes in
requirements
9
Transaction Management
• A transaction is a collection of operations that
performs a single logical function in a database
application
• Transaction-management component ensures that the
database remains in a consistent (correct) state
despite system failures (e.g., power failures and
operating system crashes) and transaction failures.
• Concurrency-control manager controls the interaction
among the concurrent transactions, to ensure the
consistency of the database.
10
Storage Management
• Storage manager is a program module that
provides the interface between the low-level
data stored in the database and the
application programs and queries submitted to
the system.
• The storage manager is responsible to the
following tasks:
interaction with the file manager
efficient storing, retrieving and updating of data
11
Overall
System
Structure
12
Application Architectures
Two-tier architecture: E.g. client programs using ODBC/JDBC
to communicate with a database
Three-tier architecture: E.g. web-based applications, and
applications built using “middleware”
13
DBMS: Allows to Create, Manipulate &
Access the Data
14
SQL
Structured Query Language
The Language of DBMS
Standard language for querying and manipulating
data. Very widely used.
1. Data Definition Language (DDL)
– Create/alter/delete tables and their attributes
2. Data Manipulation Language (DML)
– Insert/delete/modify tuples in tables
SQL
• SQL: widely used non-procedural language
– E.g. find the name of the customer with customer-id 192-83-7465
select customer.customer-name
from customer
where customer.customer-id = ‘192-83-7465’
– E.g. find the balances of all accounts held by the customer with
customer-id 192-83-7465
select account.balance
from depositor, account
where depositor.customer-id = ‘192-83-7465’ and
depositor.account-number = account.account-number
• Application programs generally access databases through one of
– Language extensions to allow embedded SQL
– Application program interface (e.g. ODBC/JDBC) which allow SQL
queries to be sent to a database 16
Tables in RDBMS
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
Product
Attribute names
Table name
Tuples or rows 17
Steps to Define the Schema
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
Product
Step 1: Define table name and its attributes
Product(PName, Price, Category, Manufacturer)
18
Basic data types
– Numeric
• Integer numbers: INTEGER, INT, and SMALLINT
• Floating-point (real) numbers: FLOAT or REAL, and
DOUBLE PRECISION
– Character-string
• Fixed length: CHAR(n), CHARACTER(n)
• Varying length: VARCHAR(n), CHAR VARYING(n),
CHARACTER VARYING(n)
Data Types and Domain of Attributes
Product(PName, Price, Category, Manfacturer)
19
Data Types and Domain of Attributes
– Boolean
• Values of TRUE or FALSE or NULL
– DATE
• Ten positions
• Components are YEAR, MONTH, and DAY in the
form YYYY-MM-DD
– Timestamp
• Includes the DATE and TIME fields
• Plus a minimum of six positions for decimal
fractions of seconds
• Optional WITH TIME ZONE qualifier 20
Step 2: Define Data Types and Domain of Attributes.
Product(PName, Price, Category, Manfacturer)
Pname : Varchar,
Price: Float,
Category: Varchar
Manfacturer: Varchar
Steps to Define the Schema
21
Constraints: Restrictions on values of
Attribute.
Step 3: Specifying Constraints.
Product(PName, Price, Category, Manfacturer)
• Specifying Key and Referential Integrity
Constraints
• Specifying Attribute and Domain Constraints
• Specifying Key Constraints
22
Specifying Attribute and Domain Constraints
• NOT NULL
NULL is not permitted for a particular attribute
• Default value
DEFAULT <value>
• CHECK clause
Dnumber > 0 AND Dnumber < 21;
• UNIQUE clause
Specifies attributes that have unique values 23
Specifying Key Constraints
• PRIMARY KEY clause
Specifies one or more attributes that make up the
primary key of a relation
 It is an attribute or a combination of attributes that
that uniquely identifies the records./tuples
e.g. roll_no, account_no, Id etc.
24
PRIMARY KEY = NOT NULL+ UNIQUE
Schema of Table Product
Product(Pname varchar Primary Key,
Price float Not Null,
Category varchar, check(Gadget, Photoraphy,
Household
Manufacturer varchar )
Attribute Data Type Constraints
Pname Varchar Primary Key
Price Float Not Null
Category Varchar Gadget,
Photography,
Household
Manufacturer Varchar
25
LET’S CODE
TOGETHER!!
26
Creating a Database
Step 1. Create a Database Company
CREATE DATABASE <DATABSE NAME>;
Create database company;
Step 2. USE Database
USE <DATABSE NAME>;
use company;
27
Step 2. SHOW TABLES
show tables;
Step 1. Create a TABLE
CREATE TABLE <TABLE NAME> (
<ATTRIBUTE LIST> <DATA TYPE> <CONSTRAINT>,
<ATTR2> <DATA TYPE>,<CONSTRAINT>);
Attribute Data Type Constraints
Pname Varchar Primary Key
Price Float Not Null
Category Varchar Gadget,
Photography,
Household
Manufacturer Varchar
Creating a Table
28
Creating a Table
VIPS: Oct - Dec 2019 29
create table product(Pname varchar(20) primary key,
price float NOT NULL,category varchar(20)
CHECK(category
in("Gadget","Photography","Household")),
manufacturer varchar(20));
Attribute Data Type Constraints
Pname Varchar Primary Key
Price Float Not Null
Category Varchar Gadget,
Photography,
Household
Manufacturer Varchar
Show tables;
Desc <tablename>;
Show Existing Tables
Describe structure of a Existing Table
30
Desc product;
INSERT INTO R(A1,…., An) VALUES (v1,…., vn)
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
Insert records in Table
31
insert into product(Pname,price,category,manufacturer)
values("Gizmo",19.99, "Gadgets", "GizmoWorks");
or
insert into product values("Gizmo",19.99, "Gadgets", "GizmoWorks");
insert into product values("Powergizmo",29.99, "Gadgets", "GizmoWorks");
insert into product values("SingleTouch",149.99, "Photography", "Canon");
insert into product values("MultiTouch",203.99, "Household", "Hitachi");
Select Query
SELECT *
FROM product;
Product
“selection”
SELECT <attributes>
FROM <one or more relations>
WHERE <conditions>
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
32
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT Pname, Price
FROM Product
Product
“projection”
Select Query using WHERE
33
PName Price
Gizmo 19.99
Powergizmo 29.99
SingleTouch 149.99
MultiTouch 203.99
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE category=‘Gadgets’;
Product
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
“selection” with
where
Select Query using WHERE
34
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT PName, Price, Manufacturer
FROM Product
WHERE Price > 100;
Product
PName Price Manufacturer
SingleTouch 149.99 Canon
MultiTouch 203.99 Hitachi
“selection” and
“projection” with
where
Select Query using WHERE
35
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT PName, Price, Manufacturer
FROM Product
WHERE Price > 100 and manufacturer =“Canon”;
Product
PName Price Manufacturer
SingleTouch 149.99 Canon
Combine two or more
conditions Using
and
Select Query using WHERE
36
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT PName, Price, Manufacturer
FROM Product
WHERE manufacturer =“Hitachi” or
manufacturer = “Canon”;
Product
Combine two or more
conditions Using
or
Select Query using WHERE
37
PName Price Manufacturer
SingleTouch 149.99 Canon
MultiTouch 203.99 Hitachi
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT PName, Price, Manufacturer
FROM Product
WHERE manufacturer IN(“Hitachi”,“Canon”);
Product
Replace OR with In
conditions Using
IN
Select Query using WHERE
38
PName Price Manufacturer
SingleTouch 149.99 Canon
MultiTouch 203.99 Hitachi
Note That
• Case insensitive:
– Same: SELECT Select select
– Same: Product product
– Different: ‘Seattle’ ‘seattle’
• Constants:
– ‘abc’ - yes
– “abc” - no
39
The LIKE operator
Pattern : pattern matching on strings. It contains two
special symbols:
% = any sequence of characters
_ = any single character
SELECT *
FROM Products
WHERE PName LIKE <pattern>
40
Like Operator with %
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE Pname like ‘p%’;
Product
PName Price Category Manufacturer
Powergizmo 29.99 Gadgets GizmoWorks
Product name that starts with P
41
Like Operator with %
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE Pname like ‘%Touch’;
Product
Product name that ends with Touch
PName Price Category Manufacturer
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
42
Like Operator with %
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE Pname like ‘%e%’;
Product
Product name that contains e anywhere in the name
PName Price Category Manufacturer
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
43
Like Operator with _ &%
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE Pname like ‘_o%’;
Product
PName Price Category Manufacturer
Powergizmo 29.99 Gadgets GizmoWorks
Product name with second letter ‘o’
44
Like Operator with %
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT *
FROM Product
WHERE Pname like ‘%c_’;
Product
Product name with second last character ‘c’
PName Price Category Manufacturer
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
45
Eliminating Duplicates
SELECT DISTINCT category
FROM Product;
Compare to:
SELECT category
FROM Product;
Category
Gadgets
Gadgets
Photography
Household
Category
Gadgets
Photography
Household
46
Aggregate Functions
Except count, all aggregations apply to a single attribute
SQL supports several aggregation operations:
 Sum
 Max
 Min
 Avg
 Count
47
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT sum(price)
FROM Product;
Product
Sum of Price of all Products
403.96
Aggregate Functions – SUM
48
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT max(price)
FROM Product;
Product
Max of Price of all Products
Aggregate Functions – MAX
203.96
49
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT min(price)
FROM Product;
Product
Min of Price of all Products
Aggregate Functions – MIN
19.99
50
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT avg(price)
FROM Product;
Product
Avg of Price of all Products
Aggregate Functions – AVG
100.99
51
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
SELECT count(price)
FROM Product;
Product
Total number of Products
Aggregate Functions – COUNT
4
52
SELECT count(*)
FROM Product;
More Examples
Query Sql
Max price of Gadgets
category Products
Select Max(price) from
product where
category=“Gadgets”
Total no of products in
Household category
Select count(*) from product
where Category=“Household”
Count total no. of categories Select
Count(Distinct(category) )
from product
53
Problem Statement SQL Query
Average Price of Gizmo Works
manufacturer ?
Total price of Gizmo Works manufacturer
?
Count total number of manufacturers
?
Count number of products that contains ‘o’
in their name
?
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
WRITE
THE
QUERY
54
Ordering the Results
SELECT pname, price, manufacturer
FROM Product
WHERE manufacturer=‘GizmoWorks’ AND price > 50
ORDER BY price, pname;
• Ties are broken by the second attribute on the ORDER
BY list, etc.
• Also works without Where
• Ordering is ascending, unless you specify the DESC
keyword.
55
SELECT pname, price, manufacturer
FROM Product
ORDER BY price DESC;
SELECT Category
FROM Product
ORDER BY PName
PName Price Category Manufacturer
Gizmo 19.99 Gadgets GizmoWorks
Powergizmo 29.99 Gadgets GizmoWorks
SingleTouch 149.99 Photography Canon
MultiTouch 203.99 Household Hitachi
?
SELECT DISTINCT category
FROM Product
ORDER BY category
SELECT DISTINCT category
FROM Product
ORDER BY PName
?
?
FIND
THE
RESULT
56
Practice Exercise
57
Attribute Data Type Constraints
Cname Varchar Primary Key
Reg_Date Date Not Null
Stock_Price Float
Country Varchar
Create a new table in your current database
‘COMPANY’ with the following schema
58
Attribute Data Type Constraints
CompName Varchar Primary Key
RegDate Date Not Null
StockPrice Float
Country Varchar
Create a new table named ‘COMPDTLS’ in your
current database with the following schema
COMPDTLS(CompName varchar Primary Key,
RegDate Date Not Null,
StockPrice Float
Country varchar )
59
Insert the following Records in COMPDTLS
CompName RegDate StockPrice Country
GizmoWorks 2019/10/21 25 USA
Canon 2019/10/3 65 Japan
Hitachi 2019/10/10 15 India
60
1. List the details of all companies
2. List the registration date of all companies
3. Show the details of all companies of Japan
4. List the company name whose stock price is 65
5. List the companies of Japan or India
6. Show the maximum stock price.
7. Show the average stock price.
8. Show the distinct countries
9. Show the total no of countries
10. Show the company name whose country name ends with ‘a’.
Write SQL Queries for:
61

More Related Content

Similar to DBMS.pptx

DBMS introduction and functionality of of dbms
DBMS introduction and functionality of  of dbmsDBMS introduction and functionality of  of dbms
DBMS introduction and functionality of of dbmsranjana dalwani
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptxSreenivas R
 
DataBase Management systems (IM).pptx
DataBase Management systems (IM).pptxDataBase Management systems (IM).pptx
DataBase Management systems (IM).pptxGooglePay16
 
Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemEddyzulham Mahluzydde
 
Dbms and it infrastructure
Dbms and  it infrastructureDbms and  it infrastructure
Dbms and it infrastructureprojectandppt
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptxChandanHegde13
 
Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Tushar Wagh
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1ahfiki
 
Database administration
Database administrationDatabase administration
Database administrationAnish Gupta
 
Data base chapter 2 | detail about the topic
Data base chapter 2 | detail about the topicData base chapter 2 | detail about the topic
Data base chapter 2 | detail about the topichoseg78377
 
Ch1
Ch1Ch1
Ch1CAG
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMSkoolkampus
 

Similar to DBMS.pptx (20)

DBMS introduction and functionality of of dbms
DBMS introduction and functionality of  of dbmsDBMS introduction and functionality of  of dbms
DBMS introduction and functionality of of dbms
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptx
 
DataBase Management systems (IM).pptx
DataBase Management systems (IM).pptxDataBase Management systems (IM).pptx
DataBase Management systems (IM).pptx
 
Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management System
 
(Dbms) class 1 & 2 (Presentation)
(Dbms) class 1 & 2 (Presentation)(Dbms) class 1 & 2 (Presentation)
(Dbms) class 1 & 2 (Presentation)
 
dbms intro
  dbms intro  dbms intro
dbms intro
 
PHP/MySQL First Session Material
PHP/MySQL First Session MaterialPHP/MySQL First Session Material
PHP/MySQL First Session Material
 
Dbms and it infrastructure
Dbms and  it infrastructureDbms and  it infrastructure
Dbms and it infrastructure
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
 
INTRODUCTION TO DATABASE
INTRODUCTION TO DATABASEINTRODUCTION TO DATABASE
INTRODUCTION TO DATABASE
 
Introduction to DBMS.pptx
Introduction to DBMS.pptxIntroduction to DBMS.pptx
Introduction to DBMS.pptx
 
Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Complete first chapter rdbm 17332
Complete first chapter rdbm 17332
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
 
Database administration
Database administrationDatabase administration
Database administration
 
Dbms
DbmsDbms
Dbms
 
Data base chapter 2 | detail about the topic
Data base chapter 2 | detail about the topicData base chapter 2 | detail about the topic
Data base chapter 2 | detail about the topic
 
Ch1
Ch1Ch1
Ch1
 
Ch1 2
Ch1 2Ch1 2
Ch1 2
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
 
Ch1
Ch1Ch1
Ch1
 

Recently uploaded

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Recently uploaded (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

DBMS.pptx

  • 2. What is a DBMS? • Collection of interrelated data – manual or computerized or online • Set of programs to access the data • DBMS provides an environment that is both convenient and efficient to use. 2
  • 3. Applications Areas of DBMS?  Banking: all transactions  Airlines: reservations, schedules  Universities: registration, grades  Sales: customers, products, purchases  Manufacturing: production, inventory, orders, supply chain  Human resources: employee records, salaries, tax deductions Databases touch all aspects of our lives 3
  • 4. • To avoid data redundancy and inconsistency Multiple file formats, duplication of information in different files • To avoid difficulty in accessing data Need to write a new program to carry out each new task • To deal with data isolation — multiple files and formats • To deal with integrity problems Integrity constraints (e.g. account balance > 0) become part of program code Easy to add new constraints or change existing ones Why do we use DBMS 4
  • 5. 1. Atomicity of updates • Failures may leave database in an inconsistent state with partial updates carried out • E.g. transfer of funds from one account to another should either complete or not happen at all 2. Concurrent access by multiple users • Concurrent accessed needed for performance • Uncontrolled concurrent accesses can lead to inconsistencies o E.g. two people reading a balance and updating it at the same time 3. Security problems Why do we use DBMS (contd..) 5
  • 6. Relational Model Example of tabular data in the relational model customer- name customer-id customer- street customer- city account- number Johnson Smith Johnson Jones Smith 192-83-7465 019-28-3746 192-83-7465 321-12-3123 019-28-3746 Alma North Alma Main North Palo Alto Rye Palo Alto Harrison Rye A-101 A-215 A-201 A-217 A-201 Attributes 6
  • 7. A Logically Related Database 7
  • 8. Database Users Users are differentiated by the way they expect to interact with the system • Application programmers – interact with system through DML calls • Sophisticated users – form requests in a database query language • Specialized users – write specialized database applications that do not fit into the traditional data processing framework • Naïve users – invoke one of the permanent application programs that have been written previously  E.g. people accessing database over the web, bank tellers, clerical staff 8
  • 9. Database Administrator • Coordinates all the activities of the database system • Has a good understanding of the enterprise’s information resources and needs. • Database administrator’s responsibilities include:  Schema definition  Storage structure and access method definition  Schema and physical organization modification  Granting user authority to access the database  Specifying integrity constraints  Acting as liaison with users  Monitoring performance and responding to changes in requirements 9
  • 10. Transaction Management • A transaction is a collection of operations that performs a single logical function in a database application • Transaction-management component ensures that the database remains in a consistent (correct) state despite system failures (e.g., power failures and operating system crashes) and transaction failures. • Concurrency-control manager controls the interaction among the concurrent transactions, to ensure the consistency of the database. 10
  • 11. Storage Management • Storage manager is a program module that provides the interface between the low-level data stored in the database and the application programs and queries submitted to the system. • The storage manager is responsible to the following tasks: interaction with the file manager efficient storing, retrieving and updating of data 11
  • 13. Application Architectures Two-tier architecture: E.g. client programs using ODBC/JDBC to communicate with a database Three-tier architecture: E.g. web-based applications, and applications built using “middleware” 13
  • 14. DBMS: Allows to Create, Manipulate & Access the Data 14
  • 15. SQL Structured Query Language The Language of DBMS Standard language for querying and manipulating data. Very widely used. 1. Data Definition Language (DDL) – Create/alter/delete tables and their attributes 2. Data Manipulation Language (DML) – Insert/delete/modify tuples in tables
  • 16. SQL • SQL: widely used non-procedural language – E.g. find the name of the customer with customer-id 192-83-7465 select customer.customer-name from customer where customer.customer-id = ‘192-83-7465’ – E.g. find the balances of all accounts held by the customer with customer-id 192-83-7465 select account.balance from depositor, account where depositor.customer-id = ‘192-83-7465’ and depositor.account-number = account.account-number • Application programs generally access databases through one of – Language extensions to allow embedded SQL – Application program interface (e.g. ODBC/JDBC) which allow SQL queries to be sent to a database 16
  • 17. Tables in RDBMS PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi Product Attribute names Table name Tuples or rows 17
  • 18. Steps to Define the Schema PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi Product Step 1: Define table name and its attributes Product(PName, Price, Category, Manufacturer) 18
  • 19. Basic data types – Numeric • Integer numbers: INTEGER, INT, and SMALLINT • Floating-point (real) numbers: FLOAT or REAL, and DOUBLE PRECISION – Character-string • Fixed length: CHAR(n), CHARACTER(n) • Varying length: VARCHAR(n), CHAR VARYING(n), CHARACTER VARYING(n) Data Types and Domain of Attributes Product(PName, Price, Category, Manfacturer) 19
  • 20. Data Types and Domain of Attributes – Boolean • Values of TRUE or FALSE or NULL – DATE • Ten positions • Components are YEAR, MONTH, and DAY in the form YYYY-MM-DD – Timestamp • Includes the DATE and TIME fields • Plus a minimum of six positions for decimal fractions of seconds • Optional WITH TIME ZONE qualifier 20
  • 21. Step 2: Define Data Types and Domain of Attributes. Product(PName, Price, Category, Manfacturer) Pname : Varchar, Price: Float, Category: Varchar Manfacturer: Varchar Steps to Define the Schema 21
  • 22. Constraints: Restrictions on values of Attribute. Step 3: Specifying Constraints. Product(PName, Price, Category, Manfacturer) • Specifying Key and Referential Integrity Constraints • Specifying Attribute and Domain Constraints • Specifying Key Constraints 22
  • 23. Specifying Attribute and Domain Constraints • NOT NULL NULL is not permitted for a particular attribute • Default value DEFAULT <value> • CHECK clause Dnumber > 0 AND Dnumber < 21; • UNIQUE clause Specifies attributes that have unique values 23
  • 24. Specifying Key Constraints • PRIMARY KEY clause Specifies one or more attributes that make up the primary key of a relation  It is an attribute or a combination of attributes that that uniquely identifies the records./tuples e.g. roll_no, account_no, Id etc. 24 PRIMARY KEY = NOT NULL+ UNIQUE
  • 25. Schema of Table Product Product(Pname varchar Primary Key, Price float Not Null, Category varchar, check(Gadget, Photoraphy, Household Manufacturer varchar ) Attribute Data Type Constraints Pname Varchar Primary Key Price Float Not Null Category Varchar Gadget, Photography, Household Manufacturer Varchar 25
  • 27. Creating a Database Step 1. Create a Database Company CREATE DATABASE <DATABSE NAME>; Create database company; Step 2. USE Database USE <DATABSE NAME>; use company; 27 Step 2. SHOW TABLES show tables;
  • 28. Step 1. Create a TABLE CREATE TABLE <TABLE NAME> ( <ATTRIBUTE LIST> <DATA TYPE> <CONSTRAINT>, <ATTR2> <DATA TYPE>,<CONSTRAINT>); Attribute Data Type Constraints Pname Varchar Primary Key Price Float Not Null Category Varchar Gadget, Photography, Household Manufacturer Varchar Creating a Table 28
  • 29. Creating a Table VIPS: Oct - Dec 2019 29 create table product(Pname varchar(20) primary key, price float NOT NULL,category varchar(20) CHECK(category in("Gadget","Photography","Household")), manufacturer varchar(20)); Attribute Data Type Constraints Pname Varchar Primary Key Price Float Not Null Category Varchar Gadget, Photography, Household Manufacturer Varchar
  • 30. Show tables; Desc <tablename>; Show Existing Tables Describe structure of a Existing Table 30 Desc product;
  • 31. INSERT INTO R(A1,…., An) VALUES (v1,…., vn) PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi Insert records in Table 31 insert into product(Pname,price,category,manufacturer) values("Gizmo",19.99, "Gadgets", "GizmoWorks"); or insert into product values("Gizmo",19.99, "Gadgets", "GizmoWorks"); insert into product values("Powergizmo",29.99, "Gadgets", "GizmoWorks"); insert into product values("SingleTouch",149.99, "Photography", "Canon"); insert into product values("MultiTouch",203.99, "Household", "Hitachi");
  • 32. Select Query SELECT * FROM product; Product “selection” SELECT <attributes> FROM <one or more relations> WHERE <conditions> PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi 32
  • 33. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT Pname, Price FROM Product Product “projection” Select Query using WHERE 33 PName Price Gizmo 19.99 Powergizmo 29.99 SingleTouch 149.99 MultiTouch 203.99
  • 34. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE category=‘Gadgets’; Product PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks “selection” with where Select Query using WHERE 34
  • 35. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT PName, Price, Manufacturer FROM Product WHERE Price > 100; Product PName Price Manufacturer SingleTouch 149.99 Canon MultiTouch 203.99 Hitachi “selection” and “projection” with where Select Query using WHERE 35
  • 36. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT PName, Price, Manufacturer FROM Product WHERE Price > 100 and manufacturer =“Canon”; Product PName Price Manufacturer SingleTouch 149.99 Canon Combine two or more conditions Using and Select Query using WHERE 36
  • 37. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT PName, Price, Manufacturer FROM Product WHERE manufacturer =“Hitachi” or manufacturer = “Canon”; Product Combine two or more conditions Using or Select Query using WHERE 37 PName Price Manufacturer SingleTouch 149.99 Canon MultiTouch 203.99 Hitachi
  • 38. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT PName, Price, Manufacturer FROM Product WHERE manufacturer IN(“Hitachi”,“Canon”); Product Replace OR with In conditions Using IN Select Query using WHERE 38 PName Price Manufacturer SingleTouch 149.99 Canon MultiTouch 203.99 Hitachi
  • 39. Note That • Case insensitive: – Same: SELECT Select select – Same: Product product – Different: ‘Seattle’ ‘seattle’ • Constants: – ‘abc’ - yes – “abc” - no 39
  • 40. The LIKE operator Pattern : pattern matching on strings. It contains two special symbols: % = any sequence of characters _ = any single character SELECT * FROM Products WHERE PName LIKE <pattern> 40
  • 41. Like Operator with % PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE Pname like ‘p%’; Product PName Price Category Manufacturer Powergizmo 29.99 Gadgets GizmoWorks Product name that starts with P 41
  • 42. Like Operator with % PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE Pname like ‘%Touch’; Product Product name that ends with Touch PName Price Category Manufacturer SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi 42
  • 43. Like Operator with % PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE Pname like ‘%e%’; Product Product name that contains e anywhere in the name PName Price Category Manufacturer Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon 43
  • 44. Like Operator with _ &% PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE Pname like ‘_o%’; Product PName Price Category Manufacturer Powergizmo 29.99 Gadgets GizmoWorks Product name with second letter ‘o’ 44
  • 45. Like Operator with % PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT * FROM Product WHERE Pname like ‘%c_’; Product Product name with second last character ‘c’ PName Price Category Manufacturer SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi 45
  • 46. Eliminating Duplicates SELECT DISTINCT category FROM Product; Compare to: SELECT category FROM Product; Category Gadgets Gadgets Photography Household Category Gadgets Photography Household 46
  • 47. Aggregate Functions Except count, all aggregations apply to a single attribute SQL supports several aggregation operations:  Sum  Max  Min  Avg  Count 47
  • 48. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT sum(price) FROM Product; Product Sum of Price of all Products 403.96 Aggregate Functions – SUM 48
  • 49. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT max(price) FROM Product; Product Max of Price of all Products Aggregate Functions – MAX 203.96 49
  • 50. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT min(price) FROM Product; Product Min of Price of all Products Aggregate Functions – MIN 19.99 50
  • 51. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT avg(price) FROM Product; Product Avg of Price of all Products Aggregate Functions – AVG 100.99 51
  • 52. PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi SELECT count(price) FROM Product; Product Total number of Products Aggregate Functions – COUNT 4 52 SELECT count(*) FROM Product;
  • 53. More Examples Query Sql Max price of Gadgets category Products Select Max(price) from product where category=“Gadgets” Total no of products in Household category Select count(*) from product where Category=“Household” Count total no. of categories Select Count(Distinct(category) ) from product 53
  • 54. Problem Statement SQL Query Average Price of Gizmo Works manufacturer ? Total price of Gizmo Works manufacturer ? Count total number of manufacturers ? Count number of products that contains ‘o’ in their name ? PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi WRITE THE QUERY 54
  • 55. Ordering the Results SELECT pname, price, manufacturer FROM Product WHERE manufacturer=‘GizmoWorks’ AND price > 50 ORDER BY price, pname; • Ties are broken by the second attribute on the ORDER BY list, etc. • Also works without Where • Ordering is ascending, unless you specify the DESC keyword. 55 SELECT pname, price, manufacturer FROM Product ORDER BY price DESC;
  • 56. SELECT Category FROM Product ORDER BY PName PName Price Category Manufacturer Gizmo 19.99 Gadgets GizmoWorks Powergizmo 29.99 Gadgets GizmoWorks SingleTouch 149.99 Photography Canon MultiTouch 203.99 Household Hitachi ? SELECT DISTINCT category FROM Product ORDER BY category SELECT DISTINCT category FROM Product ORDER BY PName ? ? FIND THE RESULT 56
  • 58. Attribute Data Type Constraints Cname Varchar Primary Key Reg_Date Date Not Null Stock_Price Float Country Varchar Create a new table in your current database ‘COMPANY’ with the following schema 58
  • 59. Attribute Data Type Constraints CompName Varchar Primary Key RegDate Date Not Null StockPrice Float Country Varchar Create a new table named ‘COMPDTLS’ in your current database with the following schema COMPDTLS(CompName varchar Primary Key, RegDate Date Not Null, StockPrice Float Country varchar ) 59
  • 60. Insert the following Records in COMPDTLS CompName RegDate StockPrice Country GizmoWorks 2019/10/21 25 USA Canon 2019/10/3 65 Japan Hitachi 2019/10/10 15 India 60
  • 61. 1. List the details of all companies 2. List the registration date of all companies 3. Show the details of all companies of Japan 4. List the company name whose stock price is 65 5. List the companies of Japan or India 6. Show the maximum stock price. 7. Show the average stock price. 8. Show the distinct countries 9. Show the total no of countries 10. Show the company name whose country name ends with ‘a’. Write SQL Queries for: 61