6.2 List, in alphabetical order, the names of all patients who had consultations after 01 January 2018. 6.3 Which practice (by name) has the most recent hire (i.e. doctor with latest employment date)? Which doctor has had the least number of consultations? Give the doctor's 6.4 name and the number of consultation s/he has given.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

"6.1,6.2 & 6.1 are answered"

The given problem has an entity relationship diagram where the requirement is to implement the diagram in the database ,  insert records in the tables and then perform the sql script execution to return the result of mentioned statements.

**As per Bartleby guidelines, solving the first 3 sub-parts as the question contains many parts and the required parts to be answered is not mentioned.

It will involve the below steps:

Converting ERD to relational schema

The database will need to create below tables: 

**Primary key is bold and underlined, Foreign key is italic

 

    1. Patient(Pat_ID, Pat_Name, Pat_Age, Pat_Gender)
    2. Doctor(Doc_ID, DOc_Name, Doc_EmployDate, Prc_ID)
    3. Consultation(Doc_ID, Pat_ID, Con_Date)
    4. Practice(Prc_ID, Prc_Name, Prc_YearEstablished, Prc_Province)
6.1 Create tables in SQL

Below is the script to create the tables with attributes and foreign key constraints: 

 

//Script will create the database named TrueHealth and then populate the tables: 

 

 

create database trueHealth;
use truehealth;
 
CREATE TABLE Patient(Pat_ID CHAR(4) primary key, Pat_Name varchar(50), Pat_Age int, Pat_Gender varchar(10));

CREATE TABLE Practice(Prc_ID int primary key, Prc_Name varchar(50), Prc_YearEstablished int, Prc_Province varchar(50));

CREATE TABLE Doctor(Doc_ID CHAR(4) primary key, Doc_Name varchar(50), Doc_EmployDate date, Prc_ID int,
constraint doc_prc foreign key (Prc_ID) references Practice(Prc_ID));

CREATE TABLE Consultation(Doc_ID char(4), Pat_ID char(4), Con_Date date,
primary key (Doc_id, Pat_id),
constraint doc_cons foreign key (Doc_ID) references Doctor(Doc_ID),
constraint pat_cons foreign key (Pat_ID) references Patient(Pat_ID) );

 

 

Result: 

Tables will get created with database:    

 

 

      

6.2 Insert records in each table

Below SQL will insert the required data in the tables as below: 

 

 


INSERT INTO PATIENT values('P001', 'PatientName1', 15,'Male');
INSERT INTO PATIENT values('P002', 'PatientName2', 35,'Female');

INSERT INTO Practice values(101, 'Padetrician', 2010, 'Gauteng');
INSERT INTO Practice values(102, 'General', 2015, 'Rohtik');

INSERT INTO DOCTOR VALUES('D001', 'DOctorname1', '2020-12-12', 101);
INSERT INTO DOCTOR VALUES('D002', 'DOctorname2', '2016-01-12', 102);

INSERT INTO CONSULTATION values('D001', 'P001', '2021-01-01');
INSERT INTO CONSULTATION values('D002', 'P001', '2016-01-01');

 

Data is each table is now as below: 

 

Patient: 

 

Doctor: 

 

Practice: 

 

Consultation: 

 

6.1: TrueHealth practices based on Gauteng

LOGIC: The requirement is to retrieve all Practice records that are having Prc_Province = Gauteng

 

SQL: Below SQL will return the required data:

 

Select * from Practice where Prc_Province = 'Gauteng'

 

Output:

 

The entity relationship diagram below models the components of a database belonging to
TrueHealth, a network of medical centers. The database allows TrueHealth to keep track
of doctors at each practice and their patients.
Patient
PK Pat ID
Consultation
Doctor
PK,FK1 Doc_ID
PK Doc ID
1..1
0..
1..1
Pat_Name
PK, FK2 Pat ID
Doc_Name
Pat Age
Con_Date
Doc_EmployDate
Pat_Gender
FK Prc_ID
0..*
1..1
Practice
PK Prc ID
Prc_Name
Prc_YearEstablished
Prc_Province
Write SQL statements for the following:
Create all the necessary tables. Name the tables; and all their attributes
appropriately.
Insert TWO records into each of the tables created to demonstrate that you
have created them correctly.
List all the TrueHealth practices based in Gauteng.
List, in alphabetical order, the names of all patients who had consultations
after 01 January 2018.
Which practice (by name) has the most recent hire (i.e. doctor with latest
employment date)?
Which doctor has had the least number of consultations? Give the doctor's
name and the number of consultation s/he has given.
6.1
6.2
6.1
6.2
6.3
6.4
Transcribed Image Text:The entity relationship diagram below models the components of a database belonging to TrueHealth, a network of medical centers. The database allows TrueHealth to keep track of doctors at each practice and their patients. Patient PK Pat ID Consultation Doctor PK,FK1 Doc_ID PK Doc ID 1..1 0.. 1..1 Pat_Name PK, FK2 Pat ID Doc_Name Pat Age Con_Date Doc_EmployDate Pat_Gender FK Prc_ID 0..* 1..1 Practice PK Prc ID Prc_Name Prc_YearEstablished Prc_Province Write SQL statements for the following: Create all the necessary tables. Name the tables; and all their attributes appropriately. Insert TWO records into each of the tables created to demonstrate that you have created them correctly. List all the TrueHealth practices based in Gauteng. List, in alphabetical order, the names of all patients who had consultations after 01 January 2018. Which practice (by name) has the most recent hire (i.e. doctor with latest employment date)? Which doctor has had the least number of consultations? Give the doctor's name and the number of consultation s/he has given. 6.1 6.2 6.1 6.2 6.3 6.4
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY