SlideShare a Scribd company logo
DATABASE
CONCEPTS
Topics
 Introducing Relational Databases
 Terminology
 Managing Databases
Introducing Relational Databases
 A relational database manages data in tables.
 Databases are managed by a relational
database management system (RDBMS).
 An RDBMS supports a database language to
create and delete databases and to manage and
search data.
 The database language used in almost all
DBMSs is SQL.
Introducing Relational Databases
 After creating a database, the most common
SQL statements used are
 INSERT to add data
 UPDATE to change data
 DELETE
 SELECT
to remove data
to search data
 A database table may have multiple columns, or
attributes, each of which has a name.
 Tables usually have a primary key, which is one
or more values that uniquely identify each row in
a table
Figure3-1. An example of relational database containing two related tables
Introducing Relational Databases
Figure 3-2. An example of relational model of the winery database
Introducing Relational Databases
 A database is modeled using entity-relationship
(ER) modeling.
(Figure 3.2.)
Terminology
 Database
 A repository to store data.
 Table
 The part of a database that stores the data. A table
has columns or attributes, and the data stored in
rows.
 Attributes
 The columns in a table. All rows in table entities have
the same attributes. For example, a customer table
might have the attributes name, address, and city.
Each attribute has a data type such as string, integer,
or date.
Terminology
 Rows
 The data entries in a table. Rows contain values for
each attribute. For example, a row in a customer
table might contain the values "Matthew Richardson,"
"Punt Road," and "Richmond." Rows are also known
as records.
 Relational model
 A model that uses tables to store data and manage
the relationship between tables.
 Relational database management system
 A software system that manages data in a database
and is based on the relational model.
Terminology
 SQL
 A query language that interacts with a DBMS. SQL is
a set of statements to manage databases, tables,
and data.
 Constraints
 Restrictions or limitations on tables and attributes.
For example, a wine can be produced only by one
winery, an order for wine can't exist if it isn't
associated with a customer, having a name attribute
could be mandatory for a customer.
9
10
Terminology
 Primary key
 One or more attributes that contain values that
uniquely identify each row. For example, a customer
table might have the primary key of cust ID. The cust
ID attribute is then assigned a unique value for each
customer. A primary key is a constraint of most
tables.
 Index
 A data structure used for fast access to rows in a
table. An index is usually built for the primary key of
each table and can then be used to quickly find a
particular row. Indexes are also defined and built for
other attributes when those attributes are frequently
used in queries.
Terminology
 Entity-relationship modeling
 A technique used to describe the real-world data in
terms of entities, attributes, and relationships.
 Normalized database
 A correctly designed database that is created from an
ER model. There are different types or levels of
normalization, and a third-normal form database is
generally regarded as being an acceptably designed
relational database.
11
Managing Databases
 The Data Definition Language (DDL) is the set of
SQL statements used to manage a database.
12
Managing Databases
 Creating Databases
 The CREATE DATABASE statement can create a
new, empty database without any tables or data.
mysql> CREATE DATABASE winestore;
mysql> use winestore
Example 3.1.
13
Managing Databases
 Creating Tables
 After issuing the use Database command, you then
usually issue commands to create the tables in the
database.
CREATE TABLE customer (
cust_id int(5) DEFAULT '0' NOT NULL auto_increment,
surname varchar(50) NOT NULL,
firstname varchar(50) NOT NULL,
……
PRIMARY KEY (cust_id),
KEY names (surname,firstname)
);
14
Managing Databases
 Altering Tables and Indexes
 Indexes can be added or removed from a table after
creation.
 To add an index to the customer table, you can issue
the following statement:
ALTER TABLE customer ADD INDEX cities (city);
 To remove an index from the customer table, use the
following statement:
ALTER TABLE customer DROP INDEX names;
15
Managing Databases
 Displaying Database Structure with SHOW
 Details of databases, tables, and indexes can be
displayed with the SHOW command.
 The SHOW command isn't part of the SQL standard
and is MySQL-specific.
 SHOW DATABASES
» Lists the databases that are accessible by the MySQL
DBMS.
 SHOW TABLES
» Shows the tables in the database once a database has
been selected with the use command.
16
Managing Databases
 SHOW COLUMNS FROM tablename
» Shows the attributes, types of attributes, key information,
whether NULL is permitted, defaults, and other information
for a table.
 SHOW INDEX FROM tablename
» Presents the details of all indexes on the table, including the
PRIMARY KEY.
 SHOW STATUS
» Reports details of the MySQL DBMS performance and
statistics.
17
Managing Databases
 Inserting, Updating, and Deleting Data
 The Data Manipulation Language (DML)
encompasses all SQL statements used for
manipulating data. There are four statements that
form the DML statement set:
»
»
»
»
SELECT
INSERT
DELETE
UPDATE
18
Managing Databases
 Inserting Data
 Having created a database and the accompanying
tables and indexes, the next step is to insert data.
 Inserting a row of data into a table can follow two
different approaches.
» First approach:
»INSERT INTO customer
»VALUES (NULL,'Marzalla','Dimitria', 'F','Mrs',
»'171 Titshall Cl','','','St Albans','WA',
»'7608','Australia','(618)63576028','',
»'dimitria@lucaston.com','1969-11-08',35000);
19
Managing Databases
»Second approach:
INSERT INTO customer
SET surname = 'Marzalla',
firstname = 'Dimitria',
initial='F',
title='Mrs',
addressline1='171 Titshall Cl',
city='St Albans',
state='WA',
zipcode='7608',
country='Australia',
phone='(618)63576028',
email='dimitria@lucaston.com',
birthdate='1969-11-08',
salary=35000;
20
Managing Databases
»The first approach can actually be varied to function in a
similar way to the second by including parenthesized
attribute names before the VALUES keyword.
INSERT INTO customer (surname,city) VALUES ('Smith','Sale');
21
Managing Databases
 Deleting Data
 There is an important distinction between dropping
and deleting in SQL.
»
»
DROP is used to remove tables or databases.
DELETE is used to remove data.
DELETE FROM customer;
DELETE FROM customer WHERE cust_id = 1;
22
Managing Databases
 Updating Data
 Data can be updated using a similar syntax to that of
the INSERT statement.
UPDATE customer SET email = lower(email);
UPDATE customer SET title = 'Dr' WHERE cust_id = 7;
23
Managing Databases
 Querying with SQL SELECT
 The SELECT statement is used to query a database
and for all output operations in SQL.
SELECT surname, firstname FROM customer;
SELECT * FROM region WHERE region_id<=3;
24
Managing Databases
 Sorting and Grouping Output
 ORDER BY
» The ORDER BY clause sorts the data after the query has been
evaluated.
SELECT surname, firstname FROM customer
WHERE title='Mr'
AND city = 'Portsea'
ORDER by surname;
25
Managing Databases
 GROUP BY
»
The GROUP BY clause is different from ORDER BY
because it doesn't sort the data for output. Instead, it sorts
the data early in the query process, for the purpose of
grouping or aggregation.
SELECT city, COUNT(*) FROM customer
GROUP BY city;
26
Managing Databases
» There are several functions that can be used in aggregation
with the GROUP BY clause. Five particularly useful functions
are:
AVG( )
Finds the average value of a numeric attribute in a set
MIN( )
Finds a minimum value of a string or numeric attribute in a
set
MAX( )
Finds a maximum value of a string or numeric attribute in a
set
SUM( )
Finds the sum total of a numeric attribute
COUNT( )
Counts the number of rows in a set
27
Managing Databases
 HAVING
» The HAVING clause permits conditional aggregation of data
into groups.
SELECT city, count(*), max(salary)
FROM customer
GROUP BY city
HAVING count(*) > 10;
28
Managing Databases
 DISTINCT
» The DISTINCT operator presents only one example of each
row from a query.
SELECT DISTINCT surname FROM customer;
29
Managing Databases
 Join Queries
 Cartesian Product
» A join query is a querying technique that matches rows from
two or more tables based on a join condition in a WHERE
clause and outputs only those rows that meet the condition.
SELECT winery_name, region_name FROM winery, region
ORDER BY winery_name, region_name;
» The query produces all possible combinations of the four
region names and 300 wineries in the sample database! In
fact, the size of the output can be accurately calculated as
the total number of rows in the first table multiplied by the
total rows in the second table. In this case, the output is 4 x
300 = 1,200 rows.
30
Managing Databases
 Elementary Natural Joins
» A cartesian product isn't the join we want. Instead, we want
to limit the results to only the sensible rows.
SELECT winery_name, region_name
FROM winery, region
WHERE winery.region_id = region.region_id
ORDER BY winery_name;
31
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE wine (
wine_id int(5) DEFAULT '0' NOT NULL auto_increment,
wine_name varchar(50) DEFAULT '' NOT NULL,
winery_id int(4),
type varchar(10) DEFAULT '' NOT NULL,
year int(4) DEFAULT '0' NOT NULL,
description blob,
PRIMARY KEY (wine_id),
KEY name (wine_name)
KEY winery (winery_id)
);
32
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE winery (
winery_id int(4) DEFAULT '0' NOT NULL auto_increment,
winery_name varchar(100) DEFAULT '' NOT NULL,
region_id int(4),
description blob,
phone varchar(15),
fax varchar(15),
PRIMARY KEY (winery_id),
KEY name (winery_name)
KEY region (region_id)
);
33
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE region (
region_id int(4) DEFAULT '0' NOT NULL auto_increment,
region_name varchar(100) DEFAULT '' NOT NULL,
description blob,
map mediumblob,
PRIMARY KEY (region_id),
KEY region (region_name)
);
34
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE customer (
cust_id int(5) NOT NULL auto_increment,
surname varchar(50) NOT NULL,
firstname varchar(50) NOT NULL,
initial char(1),
title varchar(10),
addressline1 varchar(50) NOT NULL,
addressline2 varchar(50),
addressline3 varchar(50),
city varchar(20) NOT NULL,
state varchar(20),
zipcode varchar(5),
country varchar(20),
phone varchar(15),
fax varchar(15),
email varchar(30) NOT NULL,
birth_date date( ),
salary int(7),
PRIMARY KEY (cust_id),
KEY names (surname,firstname)
);
35
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE users (
cust_id int(4) DEFAULT '0' NOT NULL,
user_name varchar(50) DEFAULT '' NOT NULL,
password varchar(15) DEFAULT '' NOT NULL,
PRIMARY KEY (user_name),
KEY password (password)
);
36
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE grape_variety (
variety_id int(3),
variety_name varchar(20),
PRIMARY KEY (variety_id),
KEY var (variety)
);
37
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE inventory (
wine_id int(5) DEFAULT '0' NOT NULL,
inventory_id int(3) NOT NULL,
on_hand int(5) NOT NULL,
cost float(5,2) NOT NULL,
case_cost float(5,2) NOT NULL,
dateadded timestamp(12) DEFAULT NULL,
PRIMARY KEY (wine_id,inventory_id)
);
38
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE orders (
cust_id int(5) DEFAULT '0' NOT NULL,
order_id int(5) DEFAULT '0' NOT NULL,
date timestamp(12),
discount float(3,1) DEFAULT '0.0',
delivery float(4,2) DEFAULT '0.00',
note varchar(120),
PRIMARY KEY (cust_id,order_no)
);
39
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE items (
cust_id int(5) DEFAULT '0' NOT NULL,
order_id int(5) DEFAULT '0' NOT NULL,
item_id int(3) DEFAULT '1' NOT NULL,
wine_id int(4) DEFAULT '0' NOT NULL
qty int(3),
price float(5,2),
date timestamp(12),
PRIMARY KEY (cust_id,order_no,item_id)
);
40
Example 3-1
Example 3-1. The complete winestore DDL statements
CREATE TABLE wine_variety (
wine_id int(5) DEFAULT '0' NOT NULL,
variety_id int(3) DEFAULT '0' NOT NULL,
id int(1) DEFAULT '0' NOT NULL,
PRIMARY KEY (wine_id, variety_id)
);
41
THANKS!
Dr Pankaj Gupta
Head – ACCESS Health Digital
digital.health@accessh.org
Twitter: @pankajguptadr, @accesshdigital
LinkedIn: drpankajgupta, accesshdigital
Ad

More Related Content

What's hot (20)

Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
zahid6
 
My Sql Work Bench
My Sql Work BenchMy Sql Work Bench
My Sql Work Bench
Lahiru Danushka
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
SQL
SQLSQL
SQL
Harshad Umredkar
 
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Atik Israk
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
Moutasm Tamimi
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
2 tier and 3 tier architecture
2 tier and 3 tier architecture2 tier and 3 tier architecture
2 tier and 3 tier architecture
baabtra.com - No. 1 supplier of quality freshers
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
Cursors
CursorsCursors
Cursors
Priyanka Yadav
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
Sharad Dubey
 
Web Database
Web DatabaseWeb Database
Web Database
idroos7
 
Relational database
Relational database Relational database
Relational database
Megha Sharma
 
Rdbms
RdbmsRdbms
Rdbms
rdbms
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Ch 2-introduction to dbms
Ch 2-introduction to dbmsCh 2-introduction to dbms
Ch 2-introduction to dbms
Rupali Rana
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
zahid6
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
Nilt1234
 
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Atik Israk
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
Moutasm Tamimi
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
Web Database
Web DatabaseWeb Database
Web Database
idroos7
 
Relational database
Relational database Relational database
Relational database
Megha Sharma
 
Rdbms
RdbmsRdbms
Rdbms
rdbms
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Ch 2-introduction to dbms
Ch 2-introduction to dbmsCh 2-introduction to dbms
Ch 2-introduction to dbms
Rupali Rana
 

Similar to Database concepts (20)

MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
webhostingguy
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
PetroJoe
 
Module 3
Module 3Module 3
Module 3
cs19club
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
NV Chandra Sekhar Nittala
 
Module02
Module02Module02
Module02
Sridhar P
 
Data base
Data baseData base
Data base
Girish Gowda
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
Ahsan Kabir
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
Information Technology
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
MLG College of Learning, Inc
 
Lab
LabLab
Lab
neelam_rawat
 
lovely
lovelylovely
lovely
love0323
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
YitbarekMurche
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
PPT SQL CLASS.pptx
PPT SQL CLASS.pptxPPT SQL CLASS.pptx
PPT SQL CLASS.pptx
AngeOuattara
 
Data Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptxData Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptx
PreeTVithule1
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Sql basics
Sql  basicsSql  basics
Sql basics
Genesis Omo
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
PetroJoe
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
Ahsan Kabir
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
PPT SQL CLASS.pptx
PPT SQL CLASS.pptxPPT SQL CLASS.pptx
PPT SQL CLASS.pptx
AngeOuattara
 
Data Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptxData Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptx
PreeTVithule1
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Ad

More from ACCESS Health Digital (20)

Governance healthcare financial lever
Governance healthcare financial lever Governance healthcare financial lever
Governance healthcare financial lever
ACCESS Health Digital
 
Startup bootcamp 3
Startup bootcamp 3Startup bootcamp 3
Startup bootcamp 3
ACCESS Health Digital
 
Startup bootcamp 2
Startup bootcamp 2Startup bootcamp 2
Startup bootcamp 2
ACCESS Health Digital
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
ACCESS Health Digital
 
Microservices
MicroservicesMicroservices
Microservices
ACCESS Health Digital
 
Java part 3
Java part  3Java part  3
Java part 3
ACCESS Health Digital
 
Java part 2
Java part  2Java part  2
Java part 2
ACCESS Health Digital
 
Java part 1
Java part 1Java part 1
Java part 1
ACCESS Health Digital
 
Hl7 & FHIR
Hl7 & FHIRHl7 & FHIR
Hl7 & FHIR
ACCESS Health Digital
 
Federated architecture
Federated architectureFederated architecture
Federated architecture
ACCESS Health Digital
 
E objects implementation
E objects implementationE objects implementation
E objects implementation
ACCESS Health Digital
 
Design patterns
Design patternsDesign patterns
Design patterns
ACCESS Health Digital
 
Computer networks
Computer networksComputer networks
Computer networks
ACCESS Health Digital
 
Cloud computing
Cloud computingCloud computing
Cloud computing
ACCESS Health Digital
 
MDDS & NDHB Principles
MDDS & NDHB PrinciplesMDDS & NDHB Principles
MDDS & NDHB Principles
ACCESS Health Digital
 
Health information exchange (HIE)
Health information exchange (HIE)Health information exchange (HIE)
Health information exchange (HIE)
ACCESS Health Digital
 
Health insurance information platform (hiip)
Health insurance information platform (hiip)Health insurance information platform (hiip)
Health insurance information platform (hiip)
ACCESS Health Digital
 
Closed loop medication administration
Closed loop medication administrationClosed loop medication administration
Closed loop medication administration
ACCESS Health Digital
 
Health delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVPHealth delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVP
ACCESS Health Digital
 
HCIT is different
HCIT is differentHCIT is different
HCIT is different
ACCESS Health Digital
 
Ad

Recently uploaded (20)

acute kidney injury. Ppt
acute kidney injury.                      Pptacute kidney injury.                      Ppt
acute kidney injury. Ppt
likhinhari
 
Controversial Ingredients : Paraben, Formaldehyde Liberators
Controversial Ingredients : Paraben, Formaldehyde LiberatorsControversial Ingredients : Paraben, Formaldehyde Liberators
Controversial Ingredients : Paraben, Formaldehyde Liberators
Rejaul Karim Ahmed
 
Anxiety Disorders ,OCD & Trauma and stress related disorder
Anxiety Disorders ,OCD & Trauma and stress related disorderAnxiety Disorders ,OCD & Trauma and stress related disorder
Anxiety Disorders ,OCD & Trauma and stress related disorder
maheswaran760921
 
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptxDr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene Arizona
 
Understanding the Benefits of Deep Tissue Massage Therapy
Understanding the Benefits of Deep Tissue Massage TherapyUnderstanding the Benefits of Deep Tissue Massage Therapy
Understanding the Benefits of Deep Tissue Massage Therapy
Fem Spa
 
Toronto First Aid: Essential Life-Saving Skills
Toronto First Aid: Essential Life-Saving SkillsToronto First Aid: Essential Life-Saving Skills
Toronto First Aid: Essential Life-Saving Skills
torontocpr3
 
Patient Safety principles in healthcare
Patient Safety  principles in healthcarePatient Safety  principles in healthcare
Patient Safety principles in healthcare
Abhimanyu Bishnu
 
National and International Health Agencies
National and International Health AgenciesNational and International Health Agencies
National and International Health Agencies
Harsh Rastogi
 
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
AbdiTofik
 
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdfChoosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Healthray Technologies Pvt. Ltd.
 
How TPAs Support Your Health Insurance Journey
How TPAs Support Your Health Insurance JourneyHow TPAs Support Your Health Insurance Journey
How TPAs Support Your Health Insurance Journey
Bedrock TPA TPA
 
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptxLiver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Sapna Thakur
 
DIGESTIVE SYSTEM (Human Anatomy and Physiology))
DIGESTIVE SYSTEM (Human Anatomy and Physiology))DIGESTIVE SYSTEM (Human Anatomy and Physiology))
DIGESTIVE SYSTEM (Human Anatomy and Physiology))
PranaliChandurkar2
 
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjfSHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
MonenusKedir
 
Laser best acne Scar Removal Cost Dwarka
Laser best acne Scar Removal Cost DwarkaLaser best acne Scar Removal Cost Dwarka
Laser best acne Scar Removal Cost Dwarka
carvers1
 
BPO in Healthcare for Enhancing Efficiency.pdf
BPO in Healthcare for Enhancing Efficiency.pdfBPO in Healthcare for Enhancing Efficiency.pdf
BPO in Healthcare for Enhancing Efficiency.pdf
AffinityCore
 
Surrogacy cost in india 2025 an overview
Surrogacy cost in india 2025 an overviewSurrogacy cost in india 2025 an overview
Surrogacy cost in india 2025 an overview
MridulPathak13
 
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdfRevolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Healthray Technologies Pvt. Ltd.
 
Radiographic Imaging findings of COPD on Conventional X-ray and CT
Radiographic Imaging findings of COPD on Conventional X-ray and CTRadiographic Imaging findings of COPD on Conventional X-ray and CT
Radiographic Imaging findings of COPD on Conventional X-ray and CT
kasambalamcbentryjun
 
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptxMenstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
SUDHA GAUTAM
 
acute kidney injury. Ppt
acute kidney injury.                      Pptacute kidney injury.                      Ppt
acute kidney injury. Ppt
likhinhari
 
Controversial Ingredients : Paraben, Formaldehyde Liberators
Controversial Ingredients : Paraben, Formaldehyde LiberatorsControversial Ingredients : Paraben, Formaldehyde Liberators
Controversial Ingredients : Paraben, Formaldehyde Liberators
Rejaul Karim Ahmed
 
Anxiety Disorders ,OCD & Trauma and stress related disorder
Anxiety Disorders ,OCD & Trauma and stress related disorderAnxiety Disorders ,OCD & Trauma and stress related disorder
Anxiety Disorders ,OCD & Trauma and stress related disorder
maheswaran760921
 
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptxDr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene on the Clinical Applications of Umbilical Cord Stem Cells.pptx
Dr. David Greene Arizona
 
Understanding the Benefits of Deep Tissue Massage Therapy
Understanding the Benefits of Deep Tissue Massage TherapyUnderstanding the Benefits of Deep Tissue Massage Therapy
Understanding the Benefits of Deep Tissue Massage Therapy
Fem Spa
 
Toronto First Aid: Essential Life-Saving Skills
Toronto First Aid: Essential Life-Saving SkillsToronto First Aid: Essential Life-Saving Skills
Toronto First Aid: Essential Life-Saving Skills
torontocpr3
 
Patient Safety principles in healthcare
Patient Safety  principles in healthcarePatient Safety  principles in healthcare
Patient Safety principles in healthcare
Abhimanyu Bishnu
 
National and International Health Agencies
National and International Health AgenciesNational and International Health Agencies
National and International Health Agencies
Harsh Rastogi
 
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
BEC Toolkit &ERL.pptxBEC Toolkit &ERL.pptx
AbdiTofik
 
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdfChoosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Choosing the Right Complaint Management Software for Your Hospital in 2025.pdf
Healthray Technologies Pvt. Ltd.
 
How TPAs Support Your Health Insurance Journey
How TPAs Support Your Health Insurance JourneyHow TPAs Support Your Health Insurance Journey
How TPAs Support Your Health Insurance Journey
Bedrock TPA TPA
 
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptxLiver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Liver_Cirrhosis_Sapna_Thakur_Presentation.pptx
Sapna Thakur
 
DIGESTIVE SYSTEM (Human Anatomy and Physiology))
DIGESTIVE SYSTEM (Human Anatomy and Physiology))DIGESTIVE SYSTEM (Human Anatomy and Physiology))
DIGESTIVE SYSTEM (Human Anatomy and Physiology))
PranaliChandurkar2
 
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjfSHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
SHOCK.pptdyyllutg;;ilsdddgdgdddddddfnggjf
MonenusKedir
 
Laser best acne Scar Removal Cost Dwarka
Laser best acne Scar Removal Cost DwarkaLaser best acne Scar Removal Cost Dwarka
Laser best acne Scar Removal Cost Dwarka
carvers1
 
BPO in Healthcare for Enhancing Efficiency.pdf
BPO in Healthcare for Enhancing Efficiency.pdfBPO in Healthcare for Enhancing Efficiency.pdf
BPO in Healthcare for Enhancing Efficiency.pdf
AffinityCore
 
Surrogacy cost in india 2025 an overview
Surrogacy cost in india 2025 an overviewSurrogacy cost in india 2025 an overview
Surrogacy cost in india 2025 an overview
MridulPathak13
 
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdfRevolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Revolutionizing Healthcare The Smart Hospital Information System Era Begins.pdf
Healthray Technologies Pvt. Ltd.
 
Radiographic Imaging findings of COPD on Conventional X-ray and CT
Radiographic Imaging findings of COPD on Conventional X-ray and CTRadiographic Imaging findings of COPD on Conventional X-ray and CT
Radiographic Imaging findings of COPD on Conventional X-ray and CT
kasambalamcbentryjun
 
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptxMenstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
Menstrual Cycle PPT / Ovarian & Uterine Cycle.pptx
SUDHA GAUTAM
 

Database concepts

  • 2. Topics  Introducing Relational Databases  Terminology  Managing Databases
  • 3. Introducing Relational Databases  A relational database manages data in tables.  Databases are managed by a relational database management system (RDBMS).  An RDBMS supports a database language to create and delete databases and to manage and search data.  The database language used in almost all DBMSs is SQL.
  • 4. Introducing Relational Databases  After creating a database, the most common SQL statements used are  INSERT to add data  UPDATE to change data  DELETE  SELECT to remove data to search data  A database table may have multiple columns, or attributes, each of which has a name.  Tables usually have a primary key, which is one or more values that uniquely identify each row in a table
  • 5. Figure3-1. An example of relational database containing two related tables Introducing Relational Databases
  • 6. Figure 3-2. An example of relational model of the winery database Introducing Relational Databases  A database is modeled using entity-relationship (ER) modeling. (Figure 3.2.)
  • 7. Terminology  Database  A repository to store data.  Table  The part of a database that stores the data. A table has columns or attributes, and the data stored in rows.  Attributes  The columns in a table. All rows in table entities have the same attributes. For example, a customer table might have the attributes name, address, and city. Each attribute has a data type such as string, integer, or date.
  • 8. Terminology  Rows  The data entries in a table. Rows contain values for each attribute. For example, a row in a customer table might contain the values "Matthew Richardson," "Punt Road," and "Richmond." Rows are also known as records.  Relational model  A model that uses tables to store data and manage the relationship between tables.  Relational database management system  A software system that manages data in a database and is based on the relational model.
  • 9. Terminology  SQL  A query language that interacts with a DBMS. SQL is a set of statements to manage databases, tables, and data.  Constraints  Restrictions or limitations on tables and attributes. For example, a wine can be produced only by one winery, an order for wine can't exist if it isn't associated with a customer, having a name attribute could be mandatory for a customer. 9
  • 10. 10 Terminology  Primary key  One or more attributes that contain values that uniquely identify each row. For example, a customer table might have the primary key of cust ID. The cust ID attribute is then assigned a unique value for each customer. A primary key is a constraint of most tables.  Index  A data structure used for fast access to rows in a table. An index is usually built for the primary key of each table and can then be used to quickly find a particular row. Indexes are also defined and built for other attributes when those attributes are frequently used in queries.
  • 11. Terminology  Entity-relationship modeling  A technique used to describe the real-world data in terms of entities, attributes, and relationships.  Normalized database  A correctly designed database that is created from an ER model. There are different types or levels of normalization, and a third-normal form database is generally regarded as being an acceptably designed relational database. 11
  • 12. Managing Databases  The Data Definition Language (DDL) is the set of SQL statements used to manage a database. 12
  • 13. Managing Databases  Creating Databases  The CREATE DATABASE statement can create a new, empty database without any tables or data. mysql> CREATE DATABASE winestore; mysql> use winestore Example 3.1. 13
  • 14. Managing Databases  Creating Tables  After issuing the use Database command, you then usually issue commands to create the tables in the database. CREATE TABLE customer ( cust_id int(5) DEFAULT '0' NOT NULL auto_increment, surname varchar(50) NOT NULL, firstname varchar(50) NOT NULL, …… PRIMARY KEY (cust_id), KEY names (surname,firstname) ); 14
  • 15. Managing Databases  Altering Tables and Indexes  Indexes can be added or removed from a table after creation.  To add an index to the customer table, you can issue the following statement: ALTER TABLE customer ADD INDEX cities (city);  To remove an index from the customer table, use the following statement: ALTER TABLE customer DROP INDEX names; 15
  • 16. Managing Databases  Displaying Database Structure with SHOW  Details of databases, tables, and indexes can be displayed with the SHOW command.  The SHOW command isn't part of the SQL standard and is MySQL-specific.  SHOW DATABASES » Lists the databases that are accessible by the MySQL DBMS.  SHOW TABLES » Shows the tables in the database once a database has been selected with the use command. 16
  • 17. Managing Databases  SHOW COLUMNS FROM tablename » Shows the attributes, types of attributes, key information, whether NULL is permitted, defaults, and other information for a table.  SHOW INDEX FROM tablename » Presents the details of all indexes on the table, including the PRIMARY KEY.  SHOW STATUS » Reports details of the MySQL DBMS performance and statistics. 17
  • 18. Managing Databases  Inserting, Updating, and Deleting Data  The Data Manipulation Language (DML) encompasses all SQL statements used for manipulating data. There are four statements that form the DML statement set: » » » » SELECT INSERT DELETE UPDATE 18
  • 19. Managing Databases  Inserting Data  Having created a database and the accompanying tables and indexes, the next step is to insert data.  Inserting a row of data into a table can follow two different approaches. » First approach: »INSERT INTO customer »VALUES (NULL,'Marzalla','Dimitria', 'F','Mrs', »'171 Titshall Cl','','','St Albans','WA', »'7608','Australia','(618)63576028','', »'[email protected]','1969-11-08',35000); 19
  • 20. Managing Databases »Second approach: INSERT INTO customer SET surname = 'Marzalla', firstname = 'Dimitria', initial='F', title='Mrs', addressline1='171 Titshall Cl', city='St Albans', state='WA', zipcode='7608', country='Australia', phone='(618)63576028', email='[email protected]', birthdate='1969-11-08', salary=35000; 20
  • 21. Managing Databases »The first approach can actually be varied to function in a similar way to the second by including parenthesized attribute names before the VALUES keyword. INSERT INTO customer (surname,city) VALUES ('Smith','Sale'); 21
  • 22. Managing Databases  Deleting Data  There is an important distinction between dropping and deleting in SQL. » » DROP is used to remove tables or databases. DELETE is used to remove data. DELETE FROM customer; DELETE FROM customer WHERE cust_id = 1; 22
  • 23. Managing Databases  Updating Data  Data can be updated using a similar syntax to that of the INSERT statement. UPDATE customer SET email = lower(email); UPDATE customer SET title = 'Dr' WHERE cust_id = 7; 23
  • 24. Managing Databases  Querying with SQL SELECT  The SELECT statement is used to query a database and for all output operations in SQL. SELECT surname, firstname FROM customer; SELECT * FROM region WHERE region_id<=3; 24
  • 25. Managing Databases  Sorting and Grouping Output  ORDER BY » The ORDER BY clause sorts the data after the query has been evaluated. SELECT surname, firstname FROM customer WHERE title='Mr' AND city = 'Portsea' ORDER by surname; 25
  • 26. Managing Databases  GROUP BY » The GROUP BY clause is different from ORDER BY because it doesn't sort the data for output. Instead, it sorts the data early in the query process, for the purpose of grouping or aggregation. SELECT city, COUNT(*) FROM customer GROUP BY city; 26
  • 27. Managing Databases » There are several functions that can be used in aggregation with the GROUP BY clause. Five particularly useful functions are: AVG( ) Finds the average value of a numeric attribute in a set MIN( ) Finds a minimum value of a string or numeric attribute in a set MAX( ) Finds a maximum value of a string or numeric attribute in a set SUM( ) Finds the sum total of a numeric attribute COUNT( ) Counts the number of rows in a set 27
  • 28. Managing Databases  HAVING » The HAVING clause permits conditional aggregation of data into groups. SELECT city, count(*), max(salary) FROM customer GROUP BY city HAVING count(*) > 10; 28
  • 29. Managing Databases  DISTINCT » The DISTINCT operator presents only one example of each row from a query. SELECT DISTINCT surname FROM customer; 29
  • 30. Managing Databases  Join Queries  Cartesian Product » A join query is a querying technique that matches rows from two or more tables based on a join condition in a WHERE clause and outputs only those rows that meet the condition. SELECT winery_name, region_name FROM winery, region ORDER BY winery_name, region_name; » The query produces all possible combinations of the four region names and 300 wineries in the sample database! In fact, the size of the output can be accurately calculated as the total number of rows in the first table multiplied by the total rows in the second table. In this case, the output is 4 x 300 = 1,200 rows. 30
  • 31. Managing Databases  Elementary Natural Joins » A cartesian product isn't the join we want. Instead, we want to limit the results to only the sensible rows. SELECT winery_name, region_name FROM winery, region WHERE winery.region_id = region.region_id ORDER BY winery_name; 31
  • 32. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE wine ( wine_id int(5) DEFAULT '0' NOT NULL auto_increment, wine_name varchar(50) DEFAULT '' NOT NULL, winery_id int(4), type varchar(10) DEFAULT '' NOT NULL, year int(4) DEFAULT '0' NOT NULL, description blob, PRIMARY KEY (wine_id), KEY name (wine_name) KEY winery (winery_id) ); 32
  • 33. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE winery ( winery_id int(4) DEFAULT '0' NOT NULL auto_increment, winery_name varchar(100) DEFAULT '' NOT NULL, region_id int(4), description blob, phone varchar(15), fax varchar(15), PRIMARY KEY (winery_id), KEY name (winery_name) KEY region (region_id) ); 33
  • 34. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE region ( region_id int(4) DEFAULT '0' NOT NULL auto_increment, region_name varchar(100) DEFAULT '' NOT NULL, description blob, map mediumblob, PRIMARY KEY (region_id), KEY region (region_name) ); 34
  • 35. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE customer ( cust_id int(5) NOT NULL auto_increment, surname varchar(50) NOT NULL, firstname varchar(50) NOT NULL, initial char(1), title varchar(10), addressline1 varchar(50) NOT NULL, addressline2 varchar(50), addressline3 varchar(50), city varchar(20) NOT NULL, state varchar(20), zipcode varchar(5), country varchar(20), phone varchar(15), fax varchar(15), email varchar(30) NOT NULL, birth_date date( ), salary int(7), PRIMARY KEY (cust_id), KEY names (surname,firstname) ); 35
  • 36. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE users ( cust_id int(4) DEFAULT '0' NOT NULL, user_name varchar(50) DEFAULT '' NOT NULL, password varchar(15) DEFAULT '' NOT NULL, PRIMARY KEY (user_name), KEY password (password) ); 36
  • 37. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE grape_variety ( variety_id int(3), variety_name varchar(20), PRIMARY KEY (variety_id), KEY var (variety) ); 37
  • 38. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE inventory ( wine_id int(5) DEFAULT '0' NOT NULL, inventory_id int(3) NOT NULL, on_hand int(5) NOT NULL, cost float(5,2) NOT NULL, case_cost float(5,2) NOT NULL, dateadded timestamp(12) DEFAULT NULL, PRIMARY KEY (wine_id,inventory_id) ); 38
  • 39. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE orders ( cust_id int(5) DEFAULT '0' NOT NULL, order_id int(5) DEFAULT '0' NOT NULL, date timestamp(12), discount float(3,1) DEFAULT '0.0', delivery float(4,2) DEFAULT '0.00', note varchar(120), PRIMARY KEY (cust_id,order_no) ); 39
  • 40. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE items ( cust_id int(5) DEFAULT '0' NOT NULL, order_id int(5) DEFAULT '0' NOT NULL, item_id int(3) DEFAULT '1' NOT NULL, wine_id int(4) DEFAULT '0' NOT NULL qty int(3), price float(5,2), date timestamp(12), PRIMARY KEY (cust_id,order_no,item_id) ); 40
  • 41. Example 3-1 Example 3-1. The complete winestore DDL statements CREATE TABLE wine_variety ( wine_id int(5) DEFAULT '0' NOT NULL, variety_id int(3) DEFAULT '0' NOT NULL, id int(1) DEFAULT '0' NOT NULL, PRIMARY KEY (wine_id, variety_id) ); 41
  • 42. THANKS! Dr Pankaj Gupta Head – ACCESS Health Digital [email protected] Twitter: @pankajguptadr, @accesshdigital LinkedIn: drpankajgupta, accesshdigital