SlideShare a Scribd company logo
Introduction to Computer Science
Databases and SQL
Lecture c
This material (Comp 4 Unit 5) was developed by Oregon Health & Science University, funded by the Department
of Health and Human Services, Office of the National Coordinator for Health Information Technology under
Award Number 90WT0001.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
Databases and SQL
Learning Objectives - 1
• Define and describe the purpose of
databases (Lecture a)
• Define a relational database (Lecture a)
• Describe data modeling and normalization
(Lecture b)
• Describe the structured query language
(SQL) (Lecture c)
2
Databases and SQL
Learning Objectives - 2
• Define the basic data operations for
relational databases and how to
implement them in SQL (Lecture c)
• Design a simple relational database and
create corresponding SQL commands
(Lecture c)
• Examine the structure of a health care
database component (Lecture d)
3
SQL
• Used to manage and access database
information
• ANSI, ISO, and IEC standard
– DBMS have custom extensions!
• Extensive language
– We will look at a few basic commands
4
Example
• Make a space for the tables by creating
the database
– create database <name>
sql> create database contacts
• To remove
– drop database <name>
sql> drop database contacts
5
Create the Tables
• Create table <name> (<column
information>);
• Column information consists of column
names and data types
• Tables also have extra information
• To remove:
– drop table <name>
6
SQL Basic Data Types
Data Type Description
integer or int Whole numbers
float Floating point number
date Date
time Time
char (length) Fixed number of characters
varchar (length) Variable number of characters
Table 1. Basic data types and their descriptions in SQL.
7
Create Company Table
sql> create table company (id
integer auto_increment,
-> name varchar(50),
-> address varchar(50),
-> city varchar(50),
-> state char(2),
-> primary key(id));
8
Create Person Table
sql> create table person(id
integer auto_increment,
-> first_name varchar(50),
-> last_name varchar(50),
-> company_id integer,
-> primary key(id),
-> foreign key(company_id)
references company(id));
9
View Tables
10
View Table Columns
11
Same Basic Operations
• Add an entry
• Retrieve an entry
• Delete an entry
• Modify an entry
12
Add an Entry
• Insert into <table> (columns) values
(values);
• First add company entries:
sql> insert into company (name, address, city, state)
-> values ('Community Hospital, Inc.', '1312 Main',
'Portland', 'OR');
sql> insert into company (name, address, city, state)
-> values ('Oakland Providers LLC', '14 12th St.',
'Oakland', 'CA');
13
Add Persons
• Now add people and companies
associated with them:
sql> insert into person (first_name, last_name, company_id)
-> values (‘Sriveni’, ‘Sharma’, 1);
sql> insert into person (first_name, last_name, company_id)
-> values (‘Walter’, ‘Chen’, 2);
sql> insert into person (first_name, last_name, company_id)
-> values (‘Rachel’, ‘Cohen’', 2);
sql> insert into person (first_name, last_name, company_id)
-> values (‘Karthik’, ‘Subramanian’, 1);
sql> insert into person (first_name, last_name, company_id)
-> values (‘Kelly’, ‘David’, 2);
14
Retrieve an Entry
• Select <columns> from <table>;
• Get company information:
15
Add Sorting
• Get people, sorted by last name:
sql> select * from person order by last_name;
16
Add Selectivity
• Get names of people who work for
Community Hospital:
sql> select first_name, last_name from where company_id = 1;
17
Retrieve from Multiple Tables
• Select <columns> from <table 1> join
<table 2> on <table 1 foreign key> =
<table 2 primary key>;
sql> select * from person join company on person.company_id = companyid;
18
Create a Complex SQL Statement
sql> select first_name, last_name, company.name from
person join company on person.company_id =
company.id order by last_name;
19
Delete an Entry
• Delete from <table> where <constraints>;
• Remove Rachel from contact list:
sql> delete from person where
first_name=‘Rachel’ and
last_name=‘Cohen’;
1 row affected
20
Modify an Entry
• update <table> set <column>=<data>
where <constraints>;
21
New Company Name - 1
• Our example where “Community Hospital,
Inc.” becomes “Community General”
– Get the id
sql> select * from company;
– Update the row data
sql> update company set name ‘Community
General’ where id=1;
22
New Company Name - 2
• Just for us, verify the change
sql> select * from company;
23
Verify Again
sql> select first_name, last_name, company.name from
person join company on person.company_id –
company.id order by last_name;
24
Databases and SQL
Summary – Lecture c
• SQL is a language for creating, accessing
and updating databases
– Create tables
– Insert data
– Update data
– Retrieve (select) data
– Delete data
25
Databases and SQL
References – Lecture c
References
Chen, P. P. (1976). The Entity-Relationship Model - Toward a Unified View of Data. ACM
Transactions on Database Systems, 1(1).
International Organization for Standardization. (2008). Information technology –
Database languages – SQL (No. ISO/IEC 9075-(1-4,9-11,13,14)).
Kent, W. (1983). A simple guide to five normal forms in relational database theory.
Communications of the ACM, 26(2).
26
Introduction to Computer Science
Databases and SQL
Lecture c
This material was developed by Oregon
Health & Science University, funded by the
Department of Health and Human Services,
Office of the National Coordinator for Health
Information Technology under Award
Number 90WT0001.
27

More Related Content

What's hot

SQL
SQLSQL
Sql injection
Sql injectionSql injection
Sql injection
Mehul Boghra
 
Mysql python
Mysql pythonMysql python
Mysql python
Janu Jahnavi
 
Mysql python
Mysql pythonMysql python
Mysql python
Janu Jahnavi
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Kazi Uddin Oly
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
oly07104
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
MS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutionsMS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutions
RSolutions
 
14 hql
14 hql14 hql
Avinash database
Avinash databaseAvinash database
Avinash database
avibmas
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07
Niit Care
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
Bertrand Matthelie
 
Sql
SqlSql
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Prashant Kumar
 
R data interfaces
R data interfacesR data interfaces
R data interfaces
Bhavesh Sarvaiya
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
Padma shree. T
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
Aditya Kumar Tripathy
 
Tutorial - Learn SQL with Live Online Database
Tutorial - Learn SQL with Live Online DatabaseTutorial - Learn SQL with Live Online Database
Tutorial - Learn SQL with Live Online Database
DBrow Adm
 
Get excelsheet
Get excelsheetGet excelsheet
Get excelsheet
myrajendra
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Ehsan Hamzei
 

What's hot (20)

SQL
SQLSQL
SQL
 
Sql injection
Sql injectionSql injection
Sql injection
 
Mysql python
Mysql pythonMysql python
Mysql python
 
Mysql python
Mysql pythonMysql python
Mysql python
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
MS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutionsMS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutions
 
14 hql
14 hql14 hql
14 hql
 
Avinash database
Avinash databaseAvinash database
Avinash database
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
Sql
SqlSql
Sql
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
R data interfaces
R data interfacesR data interfaces
R data interfaces
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Tutorial - Learn SQL with Live Online Database
Tutorial - Learn SQL with Live Online DatabaseTutorial - Learn SQL with Live Online Database
Tutorial - Learn SQL with Live Online Database
 
Get excelsheet
Get excelsheetGet excelsheet
Get excelsheet
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 

Similar to Databases and SQL - Lecture C

chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
YitbarekMurche
 
Databases with SQLite3.pdf
Databases with SQLite3.pdfDatabases with SQLite3.pdf
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
Vivek Kumar Sinha
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
Session 8 connect your universal application with database .. builders & deve...
Session 8 connect your universal application with database .. builders & deve...Session 8 connect your universal application with database .. builders & deve...
Session 8 connect your universal application with database .. builders & deve...
Moatasim Magdy
 
How Clean is your database? Data scrubbing for all skills sets
How Clean is your database? Data scrubbing for all skills setsHow Clean is your database? Data scrubbing for all skills sets
How Clean is your database? Data scrubbing for all skills sets
Chad Petrovay
 
ch4
ch4ch4
1 z0 047
1 z0 0471 z0 047
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
Pragya Rastogi
 
Sql injection
Sql injectionSql injection
Sql injection
Nitish Kumar
 
SQL basics.pptx
SQL basics.pptxSQL basics.pptx
SQL basics.pptx
ZakReeceJames
 
SQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API ConsumersSQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API Consumers
Jerod Johnson
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
zahid6
 
SQL Tutorial for Marketers
SQL Tutorial for MarketersSQL Tutorial for Marketers
SQL Tutorial for Marketers
Justin Mares
 
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
Supriya Radhakrishna
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
InfoRepos Technologies
 
Sq li
Sq liSq li
SQL(database)
SQL(database)SQL(database)
SQL(database)
welcometofacebook
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
LPhct2
 

Similar to Databases and SQL - Lecture C (20)

chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Databases with SQLite3.pdf
Databases with SQLite3.pdfDatabases with SQLite3.pdf
Databases with SQLite3.pdf
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Session 8 connect your universal application with database .. builders & deve...
Session 8 connect your universal application with database .. builders & deve...Session 8 connect your universal application with database .. builders & deve...
Session 8 connect your universal application with database .. builders & deve...
 
How Clean is your database? Data scrubbing for all skills sets
How Clean is your database? Data scrubbing for all skills setsHow Clean is your database? Data scrubbing for all skills sets
How Clean is your database? Data scrubbing for all skills sets
 
ch4
ch4ch4
ch4
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL basics.pptx
SQL basics.pptxSQL basics.pptx
SQL basics.pptx
 
SQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API ConsumersSQL for Web APIs - Simplifying Data Access for API Consumers
SQL for Web APIs - Simplifying Data Access for API Consumers
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
 
SQL Tutorial for Marketers
SQL Tutorial for MarketersSQL Tutorial for Marketers
SQL Tutorial for Marketers
 
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Sq li
Sq liSq li
Sq li
 
SQL(database)
SQL(database)SQL(database)
SQL(database)
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
 

More from CMDLearning

What is Health Informatics - Lecture B
What is Health Informatics - Lecture BWhat is Health Informatics - Lecture B
What is Health Informatics - Lecture B
CMDLearning
 
Evolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture DEvolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture D
CMDLearning
 
Evolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture CEvolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture C
CMDLearning
 
Evolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture BEvolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture B
CMDLearning
 
Evolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture AEvolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture A
CMDLearning
 
Public Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture CPublic Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture C
CMDLearning
 
Public Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture BPublic Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture B
CMDLearning
 
Public Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture APublic Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture A
CMDLearning
 
Public Health (Part 1) Lecture C
Public Health (Part 1) Lecture CPublic Health (Part 1) Lecture C
Public Health (Part 1) Lecture C
CMDLearning
 
Public Health (Part 1) Lecture B
Public Health (Part 1) Lecture BPublic Health (Part 1) Lecture B
Public Health (Part 1) Lecture B
CMDLearning
 
Public Health (Part 1) Lecture A
Public Health (Part 1) Lecture APublic Health (Part 1) Lecture A
Public Health (Part 1) Lecture A
CMDLearning
 
Regulating Healthcare - Lecture E
Regulating Healthcare - Lecture ERegulating Healthcare - Lecture E
Regulating Healthcare - Lecture E
CMDLearning
 
Regulating Healthcare - Lecture D
Regulating Healthcare - Lecture DRegulating Healthcare - Lecture D
Regulating Healthcare - Lecture D
CMDLearning
 
Regulating Healthcare - Lecture C
Regulating Healthcare - Lecture CRegulating Healthcare - Lecture C
Regulating Healthcare - Lecture C
CMDLearning
 
Regulating Healthcare - Lecture A
Regulating Healthcare - Lecture ARegulating Healthcare - Lecture A
Regulating Healthcare - Lecture A
CMDLearning
 
Regulating Healthcare - Lecture B
Regulating Healthcare - Lecture BRegulating Healthcare - Lecture B
Regulating Healthcare - Lecture B
CMDLearning
 
Financing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture CFinancing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture C
CMDLearning
 
Financing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture BFinancing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture B
CMDLearning
 
Financing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture AFinancing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture A
CMDLearning
 
Financing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture DFinancing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture D
CMDLearning
 

More from CMDLearning (20)

What is Health Informatics - Lecture B
What is Health Informatics - Lecture BWhat is Health Informatics - Lecture B
What is Health Informatics - Lecture B
 
Evolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture DEvolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture D
 
Evolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture CEvolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture C
 
Evolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture BEvolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture B
 
Evolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture AEvolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture A
 
Public Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture CPublic Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture C
 
Public Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture BPublic Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture B
 
Public Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture APublic Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture A
 
Public Health (Part 1) Lecture C
Public Health (Part 1) Lecture CPublic Health (Part 1) Lecture C
Public Health (Part 1) Lecture C
 
Public Health (Part 1) Lecture B
Public Health (Part 1) Lecture BPublic Health (Part 1) Lecture B
Public Health (Part 1) Lecture B
 
Public Health (Part 1) Lecture A
Public Health (Part 1) Lecture APublic Health (Part 1) Lecture A
Public Health (Part 1) Lecture A
 
Regulating Healthcare - Lecture E
Regulating Healthcare - Lecture ERegulating Healthcare - Lecture E
Regulating Healthcare - Lecture E
 
Regulating Healthcare - Lecture D
Regulating Healthcare - Lecture DRegulating Healthcare - Lecture D
Regulating Healthcare - Lecture D
 
Regulating Healthcare - Lecture C
Regulating Healthcare - Lecture CRegulating Healthcare - Lecture C
Regulating Healthcare - Lecture C
 
Regulating Healthcare - Lecture A
Regulating Healthcare - Lecture ARegulating Healthcare - Lecture A
Regulating Healthcare - Lecture A
 
Regulating Healthcare - Lecture B
Regulating Healthcare - Lecture BRegulating Healthcare - Lecture B
Regulating Healthcare - Lecture B
 
Financing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture CFinancing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture C
 
Financing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture BFinancing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture B
 
Financing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture AFinancing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture A
 
Financing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture DFinancing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture D
 

Recently uploaded

Gemma Wean- Nutritional solution for Artemia
Gemma Wean- Nutritional solution for ArtemiaGemma Wean- Nutritional solution for Artemia
Gemma Wean- Nutritional solution for Artemia
smuskaan0008
 
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to CareLGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
VITASAuthor
 
Professional Secrecy: Forensic Medicine Lecture
Professional Secrecy: Forensic Medicine LectureProfessional Secrecy: Forensic Medicine Lecture
Professional Secrecy: Forensic Medicine Lecture
DIVYANSHU740006
 
Trauma Outpatient Center .
Trauma Outpatient Center                       .Trauma Outpatient Center                       .
Trauma Outpatient Center .
TraumaOutpatientCent
 
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdfU Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
Jokerwigs arts and craft
 
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURYDR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
SHAMIN EABENSON
 
Feeding plate for a newborn with Cleft Palate.pptx
Feeding plate for a newborn with Cleft Palate.pptxFeeding plate for a newborn with Cleft Palate.pptx
Feeding plate for a newborn with Cleft Palate.pptx
SatvikaPrasad
 
PrudentRx's Function in the Management of Chronic Illnesses
PrudentRx's Function in the Management of Chronic IllnessesPrudentRx's Function in the Management of Chronic Illnesses
PrudentRx's Function in the Management of Chronic Illnesses
PrudentRx Program
 
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPYRECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
Isha Jaiswal
 
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
blessyjannu21
 
MBC Support Group for Black Women – Insights in Genetic Testing.pdf
MBC Support Group for Black Women – Insights in Genetic Testing.pdfMBC Support Group for Black Women – Insights in Genetic Testing.pdf
MBC Support Group for Black Women – Insights in Genetic Testing.pdf
bkling
 
NKTI Annual Report - Annual Report FY 2022
NKTI Annual Report - Annual Report FY 2022NKTI Annual Report - Annual Report FY 2022
NKTI Annual Report - Annual Report FY 2022
nktiacc3
 
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGYTime line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
DianaRodriguez639773
 
Vicarious movements or trick movements_AB.pdf
Vicarious movements or trick movements_AB.pdfVicarious movements or trick movements_AB.pdf
Vicarious movements or trick movements_AB.pdf
Arunima620542
 
The Power of Superfoods and Exercise.pdf
The Power of Superfoods and Exercise.pdfThe Power of Superfoods and Exercise.pdf
The Power of Superfoods and Exercise.pdf
Dr Rachana Gujar
 
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSONNEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
SHAMIN EABENSON
 
Letter to MREC - application to conduct study
Letter to MREC - application to conduct studyLetter to MREC - application to conduct study
Letter to MREC - application to conduct study
Azreen Aj
 
Bringing AI into a Mid-Sized Company: A structured Approach
Bringing AI into a Mid-Sized Company: A structured ApproachBringing AI into a Mid-Sized Company: A structured Approach
Bringing AI into a Mid-Sized Company: A structured Approach
Brian Frerichs
 
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
DR Jag Mohan Prajapati
 
LEAD Innovation Launch_WHO Innovation Initiative.pptx
LEAD Innovation Launch_WHO Innovation Initiative.pptxLEAD Innovation Launch_WHO Innovation Initiative.pptx
LEAD Innovation Launch_WHO Innovation Initiative.pptx
ChetanSharma78255
 

Recently uploaded (20)

Gemma Wean- Nutritional solution for Artemia
Gemma Wean- Nutritional solution for ArtemiaGemma Wean- Nutritional solution for Artemia
Gemma Wean- Nutritional solution for Artemia
 
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to CareLGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
LGBTQ+ Adults: Unique Opportunities and Inclusive Approaches to Care
 
Professional Secrecy: Forensic Medicine Lecture
Professional Secrecy: Forensic Medicine LectureProfessional Secrecy: Forensic Medicine Lecture
Professional Secrecy: Forensic Medicine Lecture
 
Trauma Outpatient Center .
Trauma Outpatient Center                       .Trauma Outpatient Center                       .
Trauma Outpatient Center .
 
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdfU Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
U Part Wigs_ A Natural Look with Minimal Effort Jokerwigs.in.pdf
 
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURYDR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
DR SHAMIN EABENSON - JOURNAL CLUB - NEEDLE STICK INJURY
 
Feeding plate for a newborn with Cleft Palate.pptx
Feeding plate for a newborn with Cleft Palate.pptxFeeding plate for a newborn with Cleft Palate.pptx
Feeding plate for a newborn with Cleft Palate.pptx
 
PrudentRx's Function in the Management of Chronic Illnesses
PrudentRx's Function in the Management of Chronic IllnessesPrudentRx's Function in the Management of Chronic Illnesses
PrudentRx's Function in the Management of Chronic Illnesses
 
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPYRECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
RECENT ADVANCES IN BREAST CANCER RADIOTHERAPY
 
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
INFECTION OF THE BRAIN -ENCEPHALITIS ( PPT)
 
MBC Support Group for Black Women – Insights in Genetic Testing.pdf
MBC Support Group for Black Women – Insights in Genetic Testing.pdfMBC Support Group for Black Women – Insights in Genetic Testing.pdf
MBC Support Group for Black Women – Insights in Genetic Testing.pdf
 
NKTI Annual Report - Annual Report FY 2022
NKTI Annual Report - Annual Report FY 2022NKTI Annual Report - Annual Report FY 2022
NKTI Annual Report - Annual Report FY 2022
 
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGYTime line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
Time line.ppQAWSDRFTGYUIOPÑLKIUYTREWASDFTGY
 
Vicarious movements or trick movements_AB.pdf
Vicarious movements or trick movements_AB.pdfVicarious movements or trick movements_AB.pdf
Vicarious movements or trick movements_AB.pdf
 
The Power of Superfoods and Exercise.pdf
The Power of Superfoods and Exercise.pdfThe Power of Superfoods and Exercise.pdf
The Power of Superfoods and Exercise.pdf
 
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSONNEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
NEEDLE STICK INJURY - JOURNAL CLUB PRESENTATION - DR SHAMIN EABENSON
 
Letter to MREC - application to conduct study
Letter to MREC - application to conduct studyLetter to MREC - application to conduct study
Letter to MREC - application to conduct study
 
Bringing AI into a Mid-Sized Company: A structured Approach
Bringing AI into a Mid-Sized Company: A structured ApproachBringing AI into a Mid-Sized Company: A structured Approach
Bringing AI into a Mid-Sized Company: A structured Approach
 
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
DELIRIUM BY DR JAGMOHAN PRAJAPATI.......
 
LEAD Innovation Launch_WHO Innovation Initiative.pptx
LEAD Innovation Launch_WHO Innovation Initiative.pptxLEAD Innovation Launch_WHO Innovation Initiative.pptx
LEAD Innovation Launch_WHO Innovation Initiative.pptx
 

Databases and SQL - Lecture C

  • 1. Introduction to Computer Science Databases and SQL Lecture c This material (Comp 4 Unit 5) was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
  • 2. Databases and SQL Learning Objectives - 1 • Define and describe the purpose of databases (Lecture a) • Define a relational database (Lecture a) • Describe data modeling and normalization (Lecture b) • Describe the structured query language (SQL) (Lecture c) 2
  • 3. Databases and SQL Learning Objectives - 2 • Define the basic data operations for relational databases and how to implement them in SQL (Lecture c) • Design a simple relational database and create corresponding SQL commands (Lecture c) • Examine the structure of a health care database component (Lecture d) 3
  • 4. SQL • Used to manage and access database information • ANSI, ISO, and IEC standard – DBMS have custom extensions! • Extensive language – We will look at a few basic commands 4
  • 5. Example • Make a space for the tables by creating the database – create database <name> sql> create database contacts • To remove – drop database <name> sql> drop database contacts 5
  • 6. Create the Tables • Create table <name> (<column information>); • Column information consists of column names and data types • Tables also have extra information • To remove: – drop table <name> 6
  • 7. SQL Basic Data Types Data Type Description integer or int Whole numbers float Floating point number date Date time Time char (length) Fixed number of characters varchar (length) Variable number of characters Table 1. Basic data types and their descriptions in SQL. 7
  • 8. Create Company Table sql> create table company (id integer auto_increment, -> name varchar(50), -> address varchar(50), -> city varchar(50), -> state char(2), -> primary key(id)); 8
  • 9. Create Person Table sql> create table person(id integer auto_increment, -> first_name varchar(50), -> last_name varchar(50), -> company_id integer, -> primary key(id), -> foreign key(company_id) references company(id)); 9
  • 12. Same Basic Operations • Add an entry • Retrieve an entry • Delete an entry • Modify an entry 12
  • 13. Add an Entry • Insert into <table> (columns) values (values); • First add company entries: sql> insert into company (name, address, city, state) -> values ('Community Hospital, Inc.', '1312 Main', 'Portland', 'OR'); sql> insert into company (name, address, city, state) -> values ('Oakland Providers LLC', '14 12th St.', 'Oakland', 'CA'); 13
  • 14. Add Persons • Now add people and companies associated with them: sql> insert into person (first_name, last_name, company_id) -> values (‘Sriveni’, ‘Sharma’, 1); sql> insert into person (first_name, last_name, company_id) -> values (‘Walter’, ‘Chen’, 2); sql> insert into person (first_name, last_name, company_id) -> values (‘Rachel’, ‘Cohen’', 2); sql> insert into person (first_name, last_name, company_id) -> values (‘Karthik’, ‘Subramanian’, 1); sql> insert into person (first_name, last_name, company_id) -> values (‘Kelly’, ‘David’, 2); 14
  • 15. Retrieve an Entry • Select <columns> from <table>; • Get company information: 15
  • 16. Add Sorting • Get people, sorted by last name: sql> select * from person order by last_name; 16
  • 17. Add Selectivity • Get names of people who work for Community Hospital: sql> select first_name, last_name from where company_id = 1; 17
  • 18. Retrieve from Multiple Tables • Select <columns> from <table 1> join <table 2> on <table 1 foreign key> = <table 2 primary key>; sql> select * from person join company on person.company_id = companyid; 18
  • 19. Create a Complex SQL Statement sql> select first_name, last_name, company.name from person join company on person.company_id = company.id order by last_name; 19
  • 20. Delete an Entry • Delete from <table> where <constraints>; • Remove Rachel from contact list: sql> delete from person where first_name=‘Rachel’ and last_name=‘Cohen’; 1 row affected 20
  • 21. Modify an Entry • update <table> set <column>=<data> where <constraints>; 21
  • 22. New Company Name - 1 • Our example where “Community Hospital, Inc.” becomes “Community General” – Get the id sql> select * from company; – Update the row data sql> update company set name ‘Community General’ where id=1; 22
  • 23. New Company Name - 2 • Just for us, verify the change sql> select * from company; 23
  • 24. Verify Again sql> select first_name, last_name, company.name from person join company on person.company_id – company.id order by last_name; 24
  • 25. Databases and SQL Summary – Lecture c • SQL is a language for creating, accessing and updating databases – Create tables – Insert data – Update data – Retrieve (select) data – Delete data 25
  • 26. Databases and SQL References – Lecture c References Chen, P. P. (1976). The Entity-Relationship Model - Toward a Unified View of Data. ACM Transactions on Database Systems, 1(1). International Organization for Standardization. (2008). Information technology – Database languages – SQL (No. ISO/IEC 9075-(1-4,9-11,13,14)). Kent, W. (1983). A simple guide to five normal forms in relational database theory. Communications of the ACM, 26(2). 26
  • 27. Introduction to Computer Science Databases and SQL Lecture c This material was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. 27

Editor's Notes

  1. Welcome to Introduction to Computer Science: Databases and SQL. This is lecture c. The component, Introduction to Computer Science, is a basic overview of computer architecture; data organization, representation and structure; structure of programming languages; networking and data communication. It also includes the basic terminology of computing.
  2. The learning objectives for Databases and SQL are to: Define and describe the purpose of databases Define a relational database Describe data modeling and normalization Describe the structured query language, or SQL
  3. Define the basic data operations for relational databases and how to implement them in SQL Design a simple relational database and create corresponding SQL commands Examine the structure of a health care database component
  4. This lecture will demonstrate how SQL is used for creating, accessing and updating databases. Structured Query Language, or SQL, is the language commonly used to manage and access a relational database. This language is a standard established by the American National Standards Institute, or ANSI, International Organization for Standardization, or ISO, and International Electrotechnical Commission, or IEC. Nevertheless, each database management system, or DBMS, may interpret the standard differently or offer proprietary extensions to the language; there is no guarantee that one set of SQL commands will work exactly the same way on another vendor’s system. Portability is difficult from one DBMS to another; however, most common commands will operate in the same fashion. While the following examples show the use of a command line interface to access the database directly through SQL commands, this is certainly not the only way to access a database. Databases can also be accessed through graphical user interfaces as well programs that issue SQL commands through defined system interfaces. The following slides will explore some basic SQL commands.
  5. To create a contacts database of individuals, their companies, and the addresses associated with those companies, use the SQL command “create database,” with the database name specified at the end of the command line. It is always helpful to use a meaningful name, so for this example, the database will be called “contacts.” In order to delete a database, the command, “drop database”, with the database name specified, is used.
  6. After the database is defined, the data tables can be created. This can be achieved with an SQL command where the table name and information about the columns contained in the database table are specified. The column information contains the name of the column as well as the type of information contained inside the specific column. Additional information about the table may also be specified. SQL has an extensive set of options available; in the following slides several examples of how to use the create command to create the tables will be explored. Just as with the database itself, a table may need to be deleted when it no longer serves its purpose. To do this, use the “drop table” command with appropriate options.
  7. This tables shows basic data types used in SQL. While SQL is a standard language, the data types, formats, and range limit of values may be vendor-specific; however, the data types shown in the table are the most common in various SQL versions. An integer data type is used to store whole numbers with no decimal points. To store a number with a decimal point, the data type needs to be identified it as a float type. If it is important to record information about when an event occurred, then both date and time data types will be indicated. Finally, there are two formats for storing textual information – char and varchar. A char is used to store strings of a known length, such as a zip code. A varchar data type is used to store text strings where the actual length is variable, such as a person’s name.
  8. This slide shows the steps to create a table for company information. It is important to remember that the company name, address, and city are of variable length, while the state will be stored as a fixed two-character abbreviation. The row will need to be uniquely identified; “id” will be used as an identifier. Finally, each column must have a meaningful name, preferably one that has an easily understandable meaning to anyone accessing the database, such as “name”. Notice that there are a few more options used in the command on this slide - the “id” column is identified as having an integer type, as well as an “auto_increment” option which instructs the system to keep track of the value, incrementing it every time a new row is added. The name, address, and city are represented as variable text strings of up to 50 characters; however, a larger value may need to be specified if names or addresses longer than 50 characters are to be stored. It was determined that the two-letter abbreviations would be used for the state names, as indicated by the “char” field value of 2. And finally, the primary, or unique, key for the company table is the “id” column.
  9. This table shows the structure for the person table. The person’s first name and last name are stored separately to enable sorting by last name only, and each person’s name is associated with a company. As in the company table, "id" is used for the primary key in this table. After names have been determined for the columns, the “create table” command is used to create the table as shown. This table is very similar to the “create company table” on the previous screen with the addition of the foreign key, company_ id, which ties the person to the appropriate company. The addition of “references company (id)” to this command tells the database that the “company id” column in the person table is tied to the “primary key (id)” column in the company database, ensuring that the company id values are consistent between the company and person tables. Also note that it is not necessary to use the same name for the foreign key in both tables; in this example, it is named "company_id" in the person table, and "id" in the company table.
  10. After the tables are created, then the “show tables” command can be used at the command line interface to confirm that the company and person tables have been correctly structured in the contacts database.
  11. To verify the correct columns and data types are in the tables, a “show columns from” command is issued for each table. Along with displaying additional detailed information, this will confirm that the individual tables have the expected names and data types, and that the primary and foreign keys, which are abbreviated in this table as PRI and MUL, have been correctly identified.
  12. There are four basic operations in an information system - adding, retrieving, deleting, and modifying information. SQL statements can be used to change the contents of database information, providing more ease and organization in the maintenance of large amounts of data.
  13. The first operation, add, is accomplished with the “insert” command in SQL. The table where information is to be inserted and the specific values for the row must be identified. This slide shows the steps to add company entries. The value for each entry in the values field lines up with the equivalent entry in the column field. For example, “city” is specified as the third column in the first insert statement and “Portland” is being used in the third column in the values field. It is imperative that the order of the values matches the order of the columns to prevent inserting wrong values into the columns. Note that a value is not specified for the id column; this was set to be auto increment when the table was created, so the system automatically enters the value. Also notice that the text strings are surrounded by single quotation marks – this is how the SQL command line interpreter recognizes the beginning and end of text.
  14. Now that the companies are entered into the database, the individuals associated with the companies can be added. For each entry, the first and last names need to be specified, again using single quotes around the text strings, and the company key. Note that this is now much simpler as only the company key associated with the person needs to be entered, rather than all of the company information. The next slide will describe how the values of 1 and 2 for the company ids are obtained.
  15. Retrieval, or selecting specific information to view, is another basic operation. In this slide, the SQL statement “select * from company” retrieves all data for every column in the table. The asterisk instructs the system to show all information. Notice that each company is numbered in the id column – this happens automatically when the “auto_increment” option is utilized as illustrated in an earlier slide.
  16. When using a file system, it can be a challenge to sort contact information by last name. By adding “order by” to the SQL statement, the system will display the information sorted by last name while maintaining the original id and “company_id” values.
  17. A search, however, may not require that all data in a record be returned. Instead of an asterisk to request everything, the names of the desired columns can be indicated in the SQL statement. This slide shows retrieval of only the first and last names of the table records. To retrieve only the first and last names of the people who are associated with a specific company – company id 1, for example - a “where company_id = 1” clause is added to the statement. Since “id 1” in this table is “Community Hospital”, the resulting table will show that Sriveni Sharma and Karthik Subramanian are associated with that organization.
  18. Previous slides have demonstrated how to retrieve information from just one table; this slide shows how to retrieve information from both tables at once. This requires a more complex SQL statement that joins the tables and specifies how the tables are related. When the two tables were created, primary keys were identified for both tables and the company id column in the person table connected to the id column in the company table. The SQL command, “select asterisk from person join company on person dot company underscore id equals company id semicolon”, connects the two tables and provides complete information on all of the contacts and the companies.
  19. This slide demonstrates an SQL statement that combines several actions - retrieving a person’s name, retrieving the name of their associated company, and sorting by last name. The SQL statement shown here selects the columns to display, indicates that information is to be collected from multiple tables, and specifies the sort order. SQL provides a large amount of flexibility in examining the data stored in a database. While this lecture has explored only a few of the options for retrieving data; there are many more SQL retrieval options that provide the user with greater control of how database data are viewed.
  20. The third basic function is deleting data, as shown on this slide. The SQL delete statement identifies the table where data will be deleted and the specific entry that is being deleted. Technically, the “where” constraint is optional, but without it, all information in the table will be deleted. A very specific SQL statement will ensure that only the specified data will be removed. There are many ways to do this; just “Rachel” could be specified, but in case there are multiple Rachels, it is best to use both the first and last names. The “id” column could have been specified instead, once Rachel’s id value was retrieved. Because it is the unique key into the table, this would guarantee that the correct row was removed.
  21. The final basic function is modifying data. SQL uses an update statement for this, where the table is identified, the columns with the data that require change are identified, the new data is identified, and the rows that are being modified are identified.
  22. This slide shows a two-step process to modify a company name from “Community Hospital, Inc.” to “Community General.” First, the unique row id will be identified using a select statement that will retrieve information on all the companies in the database. This search shows that Community Hospital, Inc. has a row id of 1, which can now be referenced in the SQL command to change the data for the hospital name. The update statement specifies company as the table, sets the contents of the name column to “Community General”, and specifies that the modification is to take place in the row with the id for the hospital. Notice again the use of single quotes to identify a text string. It is also important to know that there is no limit on the number of rows that can be changed in a single update statement. As with the delete statement, it is very important to correctly identify the rows to be changed by using the “where” clause.
  23. After the company name has been changed in the appropriate row in the company table, the change to the row information can be verified by issuing the SQL select statement and looking at the command output to ensure that the name change from “Community Hospital, Inc.” to “Community General” was successful.
  24. A final query, that pulls data from both the person and company tables, as shown on this slide, can also verify that the information has been successfully modified.
  25. This concludes lecture c of Databases and SQL. In summary, this lecture demonstrated how SQL is used for creating, accessing and updating databases. Using a contacts database as an example, SQL statements were used to create tables, insert data, update data, retrieve or select data, and delete data.
  26. References slide. No Audio.
  27. No audio.