SlideShare a Scribd company logo
1 of 58
Database Systems
Introduction to Databases and Data Warehouses
(Solutions to mini cases: MC1, MC2, MC3, MC4, MC6, MC7 )
MC1 Investco Scout
Investco Scout is an investment research company. Create the ER diagram for
the Investco Scout Funds Database, based on the following requirements.
• The Investco Scout Funds Database will keep track of investment
companies, the mutual funds they manage, and securities contained in the
mutual funds.
• For each investment company, Investco Scout will keep track of a unique
investment company identifier and a unique investment company name as
well as the names of multiple locations of the investment company.
• For each mutual fund, Investco Scout will keep track of a unique mutual
fund identifier as well as the mutual fund name and inception date.
• For each security, Investco Scout will keep track of a unique security
identifier as well as security name and type.
• Investment companies can manage multiple mutual funds. Investco
Scout does not keep track of investment companies that do not
manage any mutual funds. A mutual fund is managed by one
investment company.
• A mutual fund contains one or many securities. A security can be
included in many mutual funds. Investco Scout keeps track of
securities that are not included in any mutual funds.
• For each instance of a security included in a mutual fund, Investco
Scout keeps track of the amount included.
MC1 Investco Scout Funds: ER Diagram
MC1 Investco Scout Funds: Relational Schema
Additions to the initial requirements
• Investco Scout will keep track of the CEOFName and CEOLName for
each investment company (in addition to keeping track of a unique
investment company identifier, a unique investment company name,
and names of multiple locations of the investment company for each
investment company).
CREATE TABLE statements:
CREATE DATABASE IF NOT EXISTS MC1_Investco_Funds;
USE MC1_Investco_Funds;
CREATE TABLE COMPANY ( CompID CHAR(3) NOT NULL, CompName VARCHAR(45) NOT
NULL, CEOFname VARCHAR(25) NOT NULL, CEOLname VARCHAR(25) NOT NULL, PRIMARY
KEY (CompID), UNIQUE (CompName));
CREATE TABLE COMPANY_LocationName ( LocationName VARCHAR(25) NOT NULL, CompID
CHAR(3) NOT NULL, PRIMARY KEY (LocationName , CompID),
FOREIGN KEY (CompID) REFERENCES COMPANY (CompID));
CREATE TABLE FUND ( FundID CHAR(2) NOT NULL, FundName VARCHAR(25) NOT NULL,
InceptionDate DATE NOT NULL, Mix VARCHAR(128) NOT NULL, CompID CHAR(3) NOT NULL,
PRIMARY KEY (FundID),
FOREIGN KEY (CompID) REFERENCES COMPANY (CompID));
CREATE TABLE SECURITY ( SecurityID CHAR(3) NOT NULL, SecName VARCHAR(25) NOT
NULL, SecType VARCHAR(25) NOT NULL, PRIMARY KEY (SecurityID));
CREATE TABLE Contain ( Amount NUMERIC(7 , 2 ) NOT NULL, FundID CHAR(2) NOT NULL,
SecurityID CHAR(3) NOT NULL, PRIMARY KEY (FundID , SecurityID),
FOREIGN KEY (FundID) REFERENCES FUND (FundID),
FOREIGN KEY (SecurityID) REFERENCES SECURITY (SecurityID));
INSERT INTO statements:
INSERT INTO COMPANY VALUES ('ACF','Acme Finance','Mick','Dempsey'); INSERT INTO
COMPANY VALUES ('TCA','Tara Capital','Ava','Newton');
INSERT INTO COMAPANY VALUES ('ALB','Albritton','Lena','Dollar');
INSERT INTO COMPANY_LocationName VALUES('Chicago','ACF');
INSERT INTO COMPANY_LocationName VALUES('Denver','ACF');
INSERT INTO COMPANY_LocationName VALUES('Houston','TCA');
INSERT INTO COMPANY_LocationName VALUES('New York City','TCA');
INSERT INTO COMPANY_LocationName VALUES('Atlanta','ALB');
INSERT INTO COMPANY_LocationName VALUES('New York City','ALB');
INSERT INTO SECURITY VALUES ('AE','Abhi Engineering','Stock');
INSERT INTO SECURITY VALUES ('BH','Blues Health','Stock');
INSERT INTO SECURITY VALUES ('CM', 'County Municipality', 'Bond');
INSERT INTO SECURITY VALUES ('DU', 'Downtown Utility','Bond');
INSERT INTO SECURITY VALUES ('EM', 'Emmitt Machines','Stock');
INSERT INTO FUND(CompID, InceptionDate, FundID, FundName, Mix) VALUES ('ACF',
'2005-1-1', 'BG', 'Big Growth', '500 AE Stocks, 300 EM Stocks');
INSERT INTO FUND(CompID, InceptionDate, FundID, FundName, Mix) VALUES ('ACF',
'2006-1-1','SG','Steady Growth', '300 AE Stocks, 300 DU Bonds');
INSERT INTO FUND VALUES ('LF', 'Tiger Fund', '2005-1-1','TCA', '1000 EM Stocks, 1000
BH Stocks');
INSERT INTO FUND VALUES ('OF', 'Owl Fund', '2006-1-1','TCA', '1000 CU Bonds, 1000
DU Bonds');
INSERT INTO FUND VALUES ('JU', 'Jupiter', '2005-1-1','ALB', '2000 EM Stock, 1000 DU
Bonds');
INSERT INTO FUND VALUES ('SA', 'Saturn', '2006-1-1','ALB', '1000 EM Stock, 2000 DU
Bonds');
MC1 Investco Scout Funds in MySQL
Workbench
MC2 Funky Bizz
MC2 Funky Bizz Funky Bizz is a rental business that rents musical instruments
to bands. Create the ER diagram for the Funky Bizz Operations Database,
based on the following requirements.
• The Funky Bizz Operations Database will keep track of instruments, bands,
repair technicians, and shows. For each instrument, Funky will keep track
of a unique instrument serial number as well as the instrument model and
brand the year when the instrument was made, and the age (measured in
years) of the instrument.
• The customers of Funky Bizz are bands. For each band, Funky Bizz will keep
track of the unique band name and unique band identifier as well as the
band's address, contact person's name, and multiple phone numbers.
• Repair technicians maintain the instruments. For each technician, Funky Bizz will
keep track of a unique SSN as well as a name, ad dress, and multiple phone
numbers.
• Funky Bizz will record information about shows that its customer bands perform
in. For each show, it will keep track of a unique show identifier composed of the
show venue name and date.
• For each show it will also keep track of show type and show name (a show may or
may not have a name)
• A band does not have to rent any instruments, but may rent up to 30. Each
instrument may be rented by one band or by no bands at all
• A repair technician may repair many or no instruments, and an instrument may
be repaired by many or no technicians
• A band may perform in many shows, but does not have to perform in any. Each
show must have at least one band performing, but may have many bands
performing
• For each band, Funky Bizz keeps track of the number of shows that each band
performs in.
MC2 Funky Bizz Operations: ER Diagram
MC2 Funky Bizz Operations: Relational
Schema
* Each band may rent up to 30 instruments
CREATE TABLE Statements:
CREATE TABLE SHOWS ( Venue VARCHAR(25) NOT NULL, Date DATE NOT NULL,
Type VARCHAR(25) NOT NULL, Name VARCHAR(128), PRIMARY KEY (Venue , Date));
CREATE TABLE BAND ( BandName VARCHAR(25) NOT NULL, BandID CHAR(3) NOT
NULL, Address VARCHAR(128) NOT NULL, ContactName VARCHAR(25) NOT NULL,
PRIMARY KEY (BandID), UNIQUE (BandName));
CREATE TABLE BAND_PhoneNo ( PhoneNo VARCHAR(15) NOT NULL, BandID CHAR(3)
NOT NULL, PRIMARY KEY (PhoneNo , BandID), FOREIGN KEY (BandID)
REFERENCES BAND (BandID));
CREATE TABLE Performs ( BandID CHAR(3) NOT NULL, Venue VARCHAR(25) NOT
NULL, Date DATE NOT NULL, PRIMARY KEY (BandID , Venue , Date), FOREIGN KEY
(BandID) REFERENCES BAND (BandID), FOREIGN KEY (Venue , Date)
REFERENCES SHOWS (Venue , Date));
CREATE TABLE INSTRUMENT ( InstrumentSN VARCHAR(128) NOT NULL, Model
VARCHAR(25) NOT NULL, Brand VARCHAR(25) NOT NULL, Year INT NOT NULL,
BandID CHAR(3), PRIMARY KEY (InstrumentSN), FOREIGN KEY (BandID)
REFERENCES BAND (BandID));
CREATE TABLE REPAIRTECH ( RTSSN INT NOT NULL, RTName INT NOT NULL,
RTAddress INT NOT NULL, PRIMARY KEY (RTSSN)); CREATE TABLE
REPAIRTECH_PhoneNo ( RTPhoneNo INT NOT NULL, RTSSN INT NOT NULL,
PRIMARY KEY (RTPhoneNo , RTSSN), FOREIGN KEY (RTSSN) REFERENCES
REPAIRTECH (RTSSN));
CREATE TABLE Repairs ( InstrumentSN VARCHAR(128) NOT NULL, RTSSN INT NOT
NULL, PRIMARY KEY (InstrumentSN , RTSSN), FOREIGN KEY (InstrumentSN)
REFERENCES INSTRUMENT (InstrumentSN), FOREIGN KEY (RTSSN)
REFERENCES REPAIRTECH (RTSSN));
BEFORE INSERT / UPDATE Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC2_Funky_Bizz`.`INSTRUMENT_BEFORE_INSERT` BEFORE INSERT ON
`INSTRUMENT` FOR EACH ROW
BEGIN
DECLARE totalinstruments INT DEFAULT 0;
SELECT count(InstrumentSN) INTO totalinstruments
FROM INSTRUMENT
WHERE BandID = NEW.BandID;
IF (totalinstruments>=30) THEN
SET NEW.BandID = NULL;
SET NEW.InstrumentSN = NULL;
END IF;
END;
MC2 Funky Bizz Operations in MySQL
Workbench
MC3 Snooty Fashions
Snooty Fashions is an exclusive custom fashion designer business. Create the
ER diagram for the snooty Fashions Database based on the following
requirements . The Fashions Operations Operations Database will keep track
of the following:
• SSN as For each designer: a unique designer identifier and unique well as
the name (composed of first and last name)
• For each customer: a unique customer's identifier as well as his or her
name and multiple phone numbers.
• For each tailoring technician: a unique SSN as well as his or her name
(composed of and last name)
• For each outfit: a unique outfit's identifier as well as the outfit's planned
date of completion and its unreasonable price
• For each fashion show: a unique show identifier as well as the date of the
show and location
• Each designer designs many outfits.
• Each outfit has only one designer. Each outfit is sold (in advance) to exactly
one customer. Customers can buy one or many outfits (snooty Fashions will
not keep track of customers that have not made any purchases yet)
• Each tailoring technician must work on at least one outfit but can work on
many. Each outfit has at least one tailoring technician working on it but can
have many snooty Fashions will keep track of the date when a tailoring
technician started working on a particular outfit
• Each designer can participate in a number of fashion shows, but does not
have to participate in any. Each fashion show can feature one or two
Snooty Fashions designers (Snooty Fashions will not keep track of fashion
shows that do not feature Snooty Fashions designers).
MC3 Fashions Operations: ER Diagram
MC3 Fashions Operations: Relational Schema
*Each fashion show can feature one or two designers
CREATE TABLE Statements:
CREATE DATABASE IF NOT EXISTS MC3_Fashions_Operations;
USE MC3_Fashions_Operations;
CREATE TABLE IF NOT EXISTS DESIGNER ( DesignerID CHAR(3) NOT NULL,
DesSSN CHAR(9) NOT NULL, DesFName VARCHAR(25) NOT NULL, DesLName
VARCHAR(25) NOT NULL, PRIMARY KEY (DesignerID), UNIQUE (DesSSN));
CREATE TABLE IF NOT EXISTS FASHIONSHOW ( ShowID CHAR(3) NOT NULL,
Date DATE NOT NULL, Location VARCHAR(45) NOT NULL, PRIMARY KEY (ShowID));
CREATE TABLE IF NOT EXISTS Participates ( DesignerID CHAR(3) NOT NULL,
ShowID CHAR(3) NOT NULL, PRIMARY KEY (DesignerID , ShowID), FOREIGN KEY
(DesignerID) REFERENCES DESIGNER (DesignerID), FOREIGN KEY (ShowID)
REFERENCES FASHIONSHOW (ShowID));
CREATE TABLE IF NOT EXISTS CUSTOMER ( CustID VARCHAR(3) NOT NULL,
CustName VARCHAR(45) NOT NULL, PRIMARY KEY (CustID));CREATE TABLE IF NOT
EXISTS CUSTOMER_PhoneNo ( PhoneNo VARCHAR(15) NOT NULL, CustID
VARCHAR(3) NOT NULL, PRIMARY KEY (PhoneNo , CustID), FOREIGN KEY (CustID)
REFERENCES CUSTOMER (CustID));
CREATE TABLE IF NOT EXISTS OUTFIT ( OutfitID CHAR(10) NOT NULL,
DateOfCompletion DATE NOT NULL, Price NUMERIC(7 , 2 ) NOT NULL, DesignerID
CHAR(3) NOT NULL, CustID VARCHAR(3) NOT NULL, PRIMARY KEY (OutfitID),
FOREIGN KEY (DesignerID) REFERENCES DESIGNER (DesignerID), FOREIGN KEY
(CustID) REFERENCES CUSTOMER (CustID));
CREATE TABLE IF NOT EXISTS TECHNITIAN ( TailorSSN CHAR(9) NOT NULL,
TechLName VARCHAR(25) NOT NULL, TechFName VARCHAR(25) NOT NULL,
PRIMARY KEY (TailorSSN)); CREATE TABLE IF NOT EXISTS WorksOn ( StartDate
DATE NOT NULL, TailorSSN CHAR(9) NOT NULL, OutfitID CHAR(10) NOT NULL,
PRIMARY KEY (TailorSSN , OutfitID), FOREIGN KEY (TailorSSN) REFERENCES
TECHNITIAN (TailorSSN), FOREIGN KEY (OutfitID) REFERENCES OUTFIT
(OutfitID));
BEFORE INSERT Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC3_Fashions_Operations`.`Participates_BEFORE_INSERT` BEFORE INSERT ON
`Participates` FOR EACH ROW
BEGIN
DECLARE totaldesigners INT DEFAULT 0 ;
SELECT COUNT(*) INTO totaldesigners
FROM Participates WHERE ShowID = NEW.ShowID;
IF (totaldesigners>=2)
THEN
SET NEW.ShowID = NULL;
SET NEW.DesignerID = NULL;
END IF;
END;
BEFORE UPDATE Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC3_Fashions_Operations`.`Participates_BEFORE_UPDATE` BEFORE UPDATE ON
`Participates` FOR EACH ROW
BEGIN
DECLARE totaldesigners INT DEFAULT 0;
SELECT COUNT(*) INTO totaldesigners
FROM Participates
WHERE ShowID = NEW.ShowID;
IF (totaldesigners>=2)
THEN
SET NEW.ShowID = NULL;
SET NEW.DesignerID = NULL;
END IF;
END;
MC3 Fashions Operations in MySQL
Workbench
MC4 Signum Libri
Signum Libri (SL) is a publishing company. Create the ER diagram for the SL Operations Database
based on the following requirements. SL operations Database will keep track of the following:
• For each book SL publishes: a book name, genre, date of publication and number of pages
• For each writer: a unique writer identifier as well as the writer's name
• For each agent: a unique agent identifier as well as the agent's name
• For each editor: a unique editor identifier as well as the editor's name.
• Each SL book is written by one writer, and each writer can write many SL books. SL will not keep
track of writers who did not write a book for SL. All books written by the same writer have a
different book name. However, two writers can write two different books with the same book
name.
• Each writer is represented by one agent. Each agent represents at least one writer, but can
represent many.
• Each book has one editor. Each editor edits at least book, but can one edit many books.
• Each editor can mentor one or more other not have editors, but does to mentor any. Each editor
can have at most one mentor editor, but does not have to have any.
MC4 SL Operations: ER Diagram
MC4 SL Operations: Relational Schema
* Each editor can have at most one mentor editor
CREATE TABLE statements:
CREATE TABLE AGENT ( AgentID VARCHAR(11) NOT NULL, AgentName VARCHAR(25)
NOT NULL, PRIMARY KEY (AgentID));
CREATE TABLE WRITER ( WriterID VARCHAR(11) NOT NULL, WriterName
VARCHAR(25) NOT NULL, AgentID VARCHAR(11) NOT NULL, PRIMARY KEY
(WriterID), FOREIGN KEY (AgentID) REFERENCES AGENT (AgentID));
CREATE TABLE EDITOR ( EditorID VARCHAR(11) NOT NULL, EditorName
VARCHAR(25) NOT NULL, Mentors_EditorID VARCHAR(11) NULL, PRIMARY KEY
(EditorID), FOREIGN KEY (Mentors_EditorID) REFERENCES EDITOR (EditorID));
CREATE TABLE BOOK ( BookName VARCHAR(45) NOT NULL, Genre VARCHAR(25)
NOT NULL, DateOfPublication DATE NOT NULL, NoOfPages INT(11) NOT NULL,
WriterID VARCHAR(11) NOT NULL, EditorID VARCHAR(11) NOT NULL, PRIMARY KEY
(WriterID, BookName), FOREIGN KEY (WriterID) REFERENCES WRITER (WriterID),
FOREIGN KEY (EditorID) REFERENCES EDITOR (EditorID));
INSERT INTO statements
INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG1', 'Genady');
INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG2', 'Lola');
INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG3', 'Jose');
INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR1', 'Pascual Lorca',
'AG1');
INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR2', 'Miguel Topaz',
'AG1');
INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR3', 'Jannet Jane',
'AG2');
INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR4', 'Juan Martines',
'AG3');
INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED81', 'Julian',
NULL);
INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED82',
'Marsha', 'ED81');
INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED83', 'John',
NULL);
INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID,
EditorID) VALUES ('Jorney to it', 'Scince', '2013-01-01', 279, 'WR1', 'ED81');
INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID,
EditorID) VALUES ('Having Done', 'Fantazy', '2014-03-04', 670, 'WR1', 'ED82');
INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID,
EditorID) VALUES ('Upheval', 'Drama', '2015-02-05', 350, 'WR2', 'ED83');
INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID,
EditorID) VALUES ('Upheval', 'Comedy', '2010-08-08', 400, 'WR3', 'ED83');
MC4 SL Operations in MySQL Workbench
BEFORE INSERT Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC4_Libri_Operations`.`EDITOR_BEFORE_INSERT` BEFORE INSERT ON `EDITOR` FOR EACH
ROW
BEGIN
DECLARE totalmentors INT DEFAULT 0 ;
SELECT count(*) INTO totalmentors
FROM EDITOR
WHERE Mentors_EditorID = NEW.Mentors_EditorID;
IF (totalmentors>=1)
THEN
SET NEW.EditorID = NULL;
SET NEW.Mentors_EditorID = NULL;
END IF;
END;
BEFORE UPDATE Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC4_Libri_Operations`.`EDITOR_BEFORE_UPDATE` BEFORE UPDATE ON `EDITOR` FOR EACH
ROW
BEGIN
DECLARE totalmentors INT DEFAULT 0 ;
SELECT count(*) INTO totalmentors
FROM EDITOR
WHERE Mentors_EditorID = NEW.Mentors_EditorID;
IF (totalmentors>=1)
THEN
SET NEW.EditorID = NULL;
SET NEW.Mentors_EditorID = NULL;
END IF;
END;
MC6 Jones Dozers
Jones Dozers is a construction equipment company.
• Map the ER diagram for the Jones Dozers Sales and Rentals Database
into a relational schema.
MC6 JD Sales and Rentals: ER Diagram
MC6_JD Sales_Rentals: Relational Schema
* Each sales representative can be a protégé to maximum 1, and can mentor up to 3 other representatives
MC6_JD_Sales_Rentals in MySQL Workbench
MC6 Jones Dozers Data Warehouse
Jones Dozers wants to create an analytical database to analyze its sales and
rentals revenue. The only available data source is the Jones Sales and Rentals
Database (depicted by the ER diagram and the relational schema presented
above.
Create a dimensional model for a data warehouse that enables analysis of
sales and rentals revenue by:
• date type of revenue (sale or rental)
• customer
• equipment
• sales rep.
Each row in the fact table will represent the monetary amount of revenue
taken in during one sale or rental transaction.
MC6 JD Sales Rentals: Star Schema
MC6 Star Schema in MySQL Workbench
BEFORE UPDATE / INSERT Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`JD_Sales_Rentals`.`SALESREP_BEFORE_INSERT` BEFORE INSERT ON `SALESREP` FOR
EACH ROW
BEGIN
DECLARE totalproteges, totalmentors INT DEFAULT 0;
SET totalproteges = (SELECT count(Mentors_SRepID) FROM
JD_Sales_Rentals.SALESREP WHERE SRepID = NEW.SRepID);
SELECT count(SRepID) FROM JD_Sales_Rentals.SALESREP WHERE
Mentors_SRepID = NEW.Mentors_SRepID INTO totalmentors;
IF (totalproteges>=3 OR totalmentors >=1)
THEN
SET NEW.SRepID = NULL;
END IF;
END;
ETL INSERT INTO Statements
INSERT INTO JD_SR_Dimensional.CALENDAR (FullDate, DayOfWeek, DayOfMonth, MONTH,
Quarter, YEAR)SELECT DISTINCT Date AS FullDate, DAYOFWEEK(Date) AS DayOfWeek,
dayofmonth(Date) AS DayOfMonth, month(Date) AS MONTH, quarter(Date) AS Qtr,
year(Date) AS YEAR
FROM JD_Sales_Rentals.RENTAL UNION SELECT DISTINCT Date AS FullDate,
DAYOFWEEK(Date) AS DayOfWeek, dayofmonth(Date) AS DayOfMonth, month(Date) AS MONTH,
quarter(Date) AS Qtr, year(Date) AS YEAR FROM JD_Sales_Rentals.SALE;
INSERT INTO JD_SR_Dimensional.CUSTOMER (CustID, CustName, CustCategory) SELECT
*FROM JD_Sales_Rentals.CUSTOMER;
INSERT INTO JD_SR_Dimensional.EQUIPMENT (SerialNo, LastInspectDate, DateMade, Make,
Type, Model) SELECT E.SerialNo, E.LastInspectDate, E.DateMade, ED.Make, ED.Type, ED.Model
FROM JD_Sales_Rentals.EQUIPMENT E, JD_Sales_Rentals.EQUIPMENTDETAIL ED WHERE
E.EquipDetailID = ED.EquipDetailID;
INSERT INTO JD_SR_Dimensional.REVTYPE (RevType) VALUES ('rental'), ('sale');
INSERT INTO JD_SR_Dimensional.SALESREP (SRepID, SRepFName, SRepLName, Rank,
NoOfProteges, NoOfMentors)SELECT t1.SRepID, t1.SRepFName, t1.SRepLName, t1.Rank,
count(t1.Mentors_SRepID) as NoOfProteges, count(t2.SRepID) as NoOfMentors FROM
JD_Sales_Rentals.SALESREP t1 LEFT JOIN JD_Sales_Rentals.SALESREP t2 ON
t1.SRepID=t2.Mentors_SRepIdGROUP BY SRepID;
INSERT INTO JD_SR_Dimensional.FACT (CalendarKey, RevTypeKey, CustomerKey,
EquipmentKey, SRepKey, TID, RevenueAmount) SELECT C.CalendarKey, RT.RevTypeKey,
CU.CustomerKey, EQ.EquipmentKey, SR.SRepKey, R.RentTransID, R.Price FROM
JD_SR_Dimensional.CALENDAR AS C, JD_SR_Dimensional.REVTYPE AS RT,
JD_SR_Dimensional.CUSTOMER AS CU, JD_SR_Dimensional.EQUIPMENT AS EQ,
JD_SR_Dimensional.SALESREP AS SR, JD_Sales_Rentals.RENTAL AS R WHERE R.Date =
C.FullDate AND RT.RevType = 'rental' AND R.CustID = CU.CustID AND R.SerialNo =
EQ.SerialNo AND R.SRepID = SR.SRepID UNION SELECT C.CalendarKey, RT.RevTypeKey,
CU.CustomerKey, EQ.EquipmentKey, SR.SRepKey, S.SaleTransID, S.Price FROM
JD_SR_Dimensional.CALENDAR AS C, JD_SR_Dimensional.REVTYPE AS RT,
JD_SR_Dimensional.CUSTOMER AS CU, JD_SR_Dimensional.EQUIPMENT AS EQ,
JD_SR_Dimensional.SALESREP AS SR, JD_Sales_Rentals.SALE AS S WHERE S.Date =
C.FullDate AND RT.RevType = 'sale' AND S.CustID = CU.CustID AND S.SerialNo =
EQ.SerialNo AND S.SRepID = SR.SRepID;
MC7 Midtown Memorial
Midtown Memorial is a hospital.
• Map the ER diagram for the Midtown Memorial Patients Drug
Dispense Database into a relational schema.
MC7 Patients Drug Dispense: ER Diagram
MC7 Patients Drug Dispense: Relational
Schema
*
BEFORE UPDATE / INSERT Trigger
CREATE DEFINER = CURRENT_USER TRIGGER
`MC7_Patients_Drug_Dispensal`.`Includes_BEFORE_INSERT` BEFORE INSERT ON `Includes`
FOR EACH ROW
BEGIN
DECLARE t INT DEFAULT 0;
SELECT count(*) into t FROM MC7_Patients_Drug_Dispensal.NotToTakeWith WHERE
(DrugID_1 = NEW.DrugID AND NotTotakeWithDrugID_2 IN (SELECT DrugID FROM
MC7_Patients_Drug_Dispensal.Includes WHERE DIENumber = NEW.DIENumber and PatientID =
NEW.PatientID)) or (NotToTakeWithDrugID_2 = NEW.DrugID AND DrugID_1 IN (SELECT DrugID
FROM MC7_Patients_Drug_Dispensal.Includes WHERE DIENumber = NEW.DIENumber and
PatientID = NEW.PAtientID));
IF (t>0) THEN
SET NEW.DrugID = NULL;
END IF;
END;
MC7 Patients Drug Dispense in MySQL
Workbench
MC7 Midtown Memorial Data Warehouse
Midtown Memorial wants to create an analytical database to analyze drug ingredient
intake by their patients. The only avail- able data source is the Midtown Memorial Patients
Drug Dispensal Database and the relational schema depicted above.
Create a dimensional model for a data warehouse that enables analysis of ingredient intake
events by:
• date
• time
• patient
• nurse
• drug
• ingredient.
Each row in the fact table will represent the amount (calculated as: quantity x dosage) of
one ingredient taken by one patient during one drug intake event.
MC7 Drug Ingredient Intake: Star Schema
MC7 Star Schema in MySQL Workbench
ETL INSERT INTO Statements
INSERT INTO MC7_Ingredient_Intake.CALENDAR (FullDate, DayOfWeek, DayOfMonth,
Month, Qtr, YEAR)SELECT DISTINCT DIEDate AS FullDate, DAYOFWEEK(DIEDate) AS
DayOfWeek, dayofmonth(DIEDate) AS DayOfMonth, month(DIEDate) AS MONTH,
quarter(DIEDate) AS Qtr, year(DIEDate) AS YEAR FROM
MC7_Patients_Drug_Dispensal.DRUGINTAKEEVENT;
INSERT INTO MC7_Ingredient_Intake.PATIENT (PatientID, PatientLName, PatientFName,
PatientGender, PatientBDate) SELECT *FROM MC7_Patients_Drug_Dispensal.PATIENT;
INSERT INTO MC7_Ingredient_Intake.NURSE (NurseID, NurseName)SELECT *FROM
MC7_Patients_Drug_Dispensal.NURSE;
INSERT INTO MC7_Ingredient_Intake.DRUG (DrugID, DrugName, DrugCoatingType)
SELECT *FROM MC7_Patients_Drug_Dispensal.DRUG;
INSERT INTO MC7_Ingredient_Intake.INGREDIENT (IngID, IngName) SELECT *FROM
MC7_Patients_Drug_Dispensal.INGREDIENT;
INSERT INTO MC7_Ingredient_Intake.DRUG_INTAKE_EVENT (CalendarKey, PatientKey,
NurseKey, DrugKey, IngredientKey, DIENumber, QuantityxDosage, DIETime)SELECT
C.CalendarKey, P.PatientKey, N.NurseKey, D.DrugKey, I.IngredientKey, DIE.DIENumber,
INC.Quantity * CON.Dosage, DIE.DIETime FROM MC7_Ingredient_Intake.CALENDAR AS
C, MC7_Ingredient_Intake.PATIENT AS P, MC7_Ingredient_Intake.NURSE AS N,
MC7_Ingredient_Intake.DRUG AS D, MC7_Ingredient_Intake.INGREDIENT AS I,
MC7_Patients_Drug_Dispensal.DRUGINTAKEEVENT AS DIE,
MC7_Patients_Drug_Dispensal.Includes AS INC, MC7_Patients_Drug_Dispensal.Contain
AS CON WHERE DIE.DIEDate = C.FullDate AND DIE.PatientID = P.PatientID AND
DIE.NurseID = N.NurseID AND INC.DrugID = D.DrugID AND CON.IngID = I.IngID AND
CON.DrugID = INC.DrugID AND INC.DIENumber = DIE.DIENumber AND INC.PatientID =
DIE.PatientID ORDER BY DIENumber, DrugKey;
References:
Jukic N., Vrbsky S., Nestorov S. “Database Systems. Introduction to
Databases and Data Warehouses”. Pearson Education Inc., 2014.

More Related Content

What's hot (14)

Nike vs. Adidas PowerPoint
Nike vs. Adidas PowerPointNike vs. Adidas PowerPoint
Nike vs. Adidas PowerPoint
 
Marketing strategy of Hotstar
Marketing strategy of HotstarMarketing strategy of Hotstar
Marketing strategy of Hotstar
 
Date and time functions in mysql
Date and time functions in mysqlDate and time functions in mysql
Date and time functions in mysql
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
File organization and introduction of DBMS
File organization and introduction of DBMSFile organization and introduction of DBMS
File organization and introduction of DBMS
 
SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
Андрей Кожанов. ЧТО ЛЬЗЯ В БРЕНД-ДИЗАЙНЕ. Или где живет дизайн в проектирован...
Андрей Кожанов. ЧТО ЛЬЗЯ В БРЕНД-ДИЗАЙНЕ. Или где живет дизайн в проектирован...Андрей Кожанов. ЧТО ЛЬЗЯ В БРЕНД-ДИЗАЙНЕ. Или где живет дизайн в проектирован...
Андрей Кожанов. ЧТО ЛЬЗЯ В БРЕНД-ДИЗАЙНЕ. Или где живет дизайн в проектирован...
 
Cursores.ppt
Cursores.pptCursores.ppt
Cursores.ppt
 
DBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCLDBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCL
 
Database anomalies
Database anomaliesDatabase anomalies
Database anomalies
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
SQL practice questions set - 2
SQL practice questions set - 2SQL practice questions set - 2
SQL practice questions set - 2
 
HBR Hulu Case Study Analysis
HBR Hulu Case Study Analysis HBR Hulu Case Study Analysis
HBR Hulu Case Study Analysis
 
All questions
All questionsAll questions
All questions
 

Viewers also liked

04 Classification in Data Mining
04 Classification in Data Mining04 Classification in Data Mining
04 Classification in Data MiningValerii Klymchuk
 
01 Introduction to Data Mining
01 Introduction to Data Mining01 Introduction to Data Mining
01 Introduction to Data MiningValerii Klymchuk
 
05 Clustering in Data Mining
05 Clustering in Data Mining05 Clustering in Data Mining
05 Clustering in Data MiningValerii Klymchuk
 
Artificial Intelligence for Automated Decision Support Project
Artificial Intelligence for Automated Decision Support ProjectArtificial Intelligence for Automated Decision Support Project
Artificial Intelligence for Automated Decision Support ProjectValerii Klymchuk
 
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι ΔεδομένωνFotis Kokkoras
 
04 - SQL (μέρος 2)
04 - SQL (μέρος 2)04 - SQL (μέρος 2)
04 - SQL (μέρος 2)Fotis Kokkoras
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sqldeathsubte
 
Mapping Relational Databases to Linked Data
Mapping Relational Databases to Linked DataMapping Relational Databases to Linked Data
Mapping Relational Databases to Linked DataEUCLID project
 
Pharmacy management
Pharmacy managementPharmacy management
Pharmacy managementRasel Khan
 
Assignment 1 of Database (MySQL & Sqlite3)
Assignment 1 of Database (MySQL & Sqlite3) Assignment 1 of Database (MySQL & Sqlite3)
Assignment 1 of Database (MySQL & Sqlite3) Aey Unthika
 

Viewers also liked (20)

02 Related Concepts
02 Related Concepts02 Related Concepts
02 Related Concepts
 
04 Classification in Data Mining
04 Classification in Data Mining04 Classification in Data Mining
04 Classification in Data Mining
 
03 Data Mining Techniques
03 Data Mining Techniques03 Data Mining Techniques
03 Data Mining Techniques
 
01 Introduction to Data Mining
01 Introduction to Data Mining01 Introduction to Data Mining
01 Introduction to Data Mining
 
05 Clustering in Data Mining
05 Clustering in Data Mining05 Clustering in Data Mining
05 Clustering in Data Mining
 
Artificial Intelligence for Automated Decision Support Project
Artificial Intelligence for Automated Decision Support ProjectArtificial Intelligence for Automated Decision Support Project
Artificial Intelligence for Automated Decision Support Project
 
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων
02 - Σχεσιακό Μοντέλο (Βασικές Έννοιες) - Τύποι Δεδομένων
 
04 - SQL (μέρος 2)
04 - SQL (μέρος 2)04 - SQL (μέρος 2)
04 - SQL (μέρος 2)
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
 
Ontology based metadata schema for digital library projects in China
Ontology based metadata schema for digital library projects in ChinaOntology based metadata schema for digital library projects in China
Ontology based metadata schema for digital library projects in China
 
2 erd
2 erd2 erd
2 erd
 
Mapping Relational Databases to Linked Data
Mapping Relational Databases to Linked DataMapping Relational Databases to Linked Data
Mapping Relational Databases to Linked Data
 
Solution4(database)
Solution4(database)Solution4(database)
Solution4(database)
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Solution3(database)
Solution3(database)Solution3(database)
Solution3(database)
 
Solution2(database)
Solution2(database)Solution2(database)
Solution2(database)
 
Pharmacy management
Pharmacy managementPharmacy management
Pharmacy management
 
Solution4 1(database)
Solution4 1(database)Solution4 1(database)
Solution4 1(database)
 
03 Data Representation
03 Data Representation03 Data Representation
03 Data Representation
 
Assignment 1 of Database (MySQL & Sqlite3)
Assignment 1 of Database (MySQL & Sqlite3) Assignment 1 of Database (MySQL & Sqlite3)
Assignment 1 of Database (MySQL & Sqlite3)
 

Similar to Database Project

J. Adcock Bi Portfolio
J. Adcock   Bi PortfolioJ. Adcock   Bi Portfolio
J. Adcock Bi PortfolioJerry Adcock
 
ERD Activity.pptx
ERD Activity.pptxERD Activity.pptx
ERD Activity.pptxEdFeranil
 
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docxBMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docxhartrobert670
 
CMS Project Phase II InstructionsIn this phase, you will create t.docx
CMS Project Phase II InstructionsIn this phase, you will create t.docxCMS Project Phase II InstructionsIn this phase, you will create t.docx
CMS Project Phase II InstructionsIn this phase, you will create t.docxmary772
 
Tcm step 3 venture assessment
Tcm step 3 venture assessmentTcm step 3 venture assessment
Tcm step 3 venture assessmentStephen Ong
 
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data Modeling
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data ModelingCassandra Day SV 2014: Fundamentals of Apache Cassandra Data Modeling
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data ModelingDataStax Academy
 
De l'autre côté du miroir
De l'autre côté du miroirDe l'autre côté du miroir
De l'autre côté du miroirThomas Pierrain
 
Database Design Project-Oracle 11g
Database Design  Project-Oracle 11g Database Design  Project-Oracle 11g
Database Design Project-Oracle 11g Sunny U Okoro
 
Group Project 650 Report2
Group Project 650 Report2Group Project 650 Report2
Group Project 650 Report2Yazeed Alkarzai
 
SQL Server 2008 Portfolio
SQL Server 2008 PortfolioSQL Server 2008 Portfolio
SQL Server 2008 Portfoliolilredlokita
 
Chapter 5
Chapter 5Chapter 5
Chapter 5detjen
 
Car Rental Agency - Database - MySQL
Car Rental Agency - Database - MySQLCar Rental Agency - Database - MySQL
Car Rental Agency - Database - MySQLSotiris Baratsas
 
U.S. Machine Tool Market. Analysis And Forecast to 2020
U.S. Machine Tool Market. Analysis And Forecast to 2020U.S. Machine Tool Market. Analysis And Forecast to 2020
U.S. Machine Tool Market. Analysis And Forecast to 2020IndexBox Marketing
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENTLori Moore
 
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...IndexBox Marketing
 
eBusiness Website Database Design
eBusiness Website Database DesigneBusiness Website Database Design
eBusiness Website Database DesignMeng (Meg) Wang
 

Similar to Database Project (16)

J. Adcock Bi Portfolio
J. Adcock   Bi PortfolioJ. Adcock   Bi Portfolio
J. Adcock Bi Portfolio
 
ERD Activity.pptx
ERD Activity.pptxERD Activity.pptx
ERD Activity.pptx
 
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docxBMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
BMIS 325CMS Project Phase II InstructionsIn this phase, you w.docx
 
CMS Project Phase II InstructionsIn this phase, you will create t.docx
CMS Project Phase II InstructionsIn this phase, you will create t.docxCMS Project Phase II InstructionsIn this phase, you will create t.docx
CMS Project Phase II InstructionsIn this phase, you will create t.docx
 
Tcm step 3 venture assessment
Tcm step 3 venture assessmentTcm step 3 venture assessment
Tcm step 3 venture assessment
 
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data Modeling
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data ModelingCassandra Day SV 2014: Fundamentals of Apache Cassandra Data Modeling
Cassandra Day SV 2014: Fundamentals of Apache Cassandra Data Modeling
 
De l'autre côté du miroir
De l'autre côté du miroirDe l'autre côté du miroir
De l'autre côté du miroir
 
Database Design Project-Oracle 11g
Database Design  Project-Oracle 11g Database Design  Project-Oracle 11g
Database Design Project-Oracle 11g
 
Group Project 650 Report2
Group Project 650 Report2Group Project 650 Report2
Group Project 650 Report2
 
SQL Server 2008 Portfolio
SQL Server 2008 PortfolioSQL Server 2008 Portfolio
SQL Server 2008 Portfolio
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Car Rental Agency - Database - MySQL
Car Rental Agency - Database - MySQLCar Rental Agency - Database - MySQL
Car Rental Agency - Database - MySQL
 
U.S. Machine Tool Market. Analysis And Forecast to 2020
U.S. Machine Tool Market. Analysis And Forecast to 2020U.S. Machine Tool Market. Analysis And Forecast to 2020
U.S. Machine Tool Market. Analysis And Forecast to 2020
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
 
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...
U.S. Showcase, Partition, Shelving, And Locker Market. Analysis And Forecast ...
 
eBusiness Website Database Design
eBusiness Website Database DesigneBusiness Website Database Design
eBusiness Website Database Design
 

More from Valerii Klymchuk

Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides templateValerii Klymchuk
 
Crime Analysis based on Historical and Transportation Data
Crime Analysis based on Historical and Transportation DataCrime Analysis based on Historical and Transportation Data
Crime Analysis based on Historical and Transportation DataValerii Klymchuk
 

More from Valerii Klymchuk (6)

Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides template
 
Toronto Capstone
Toronto CapstoneToronto Capstone
Toronto Capstone
 
05 Scalar Visualization
05 Scalar Visualization05 Scalar Visualization
05 Scalar Visualization
 
06 Vector Visualization
06 Vector Visualization06 Vector Visualization
06 Vector Visualization
 
07 Tensor Visualization
07 Tensor Visualization07 Tensor Visualization
07 Tensor Visualization
 
Crime Analysis based on Historical and Transportation Data
Crime Analysis based on Historical and Transportation DataCrime Analysis based on Historical and Transportation Data
Crime Analysis based on Historical and Transportation Data
 

Recently uploaded

B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationBoston Institute of Analytics
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 

Recently uploaded (20)

VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health Classification
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
Call Girls In Noida City Center Metro 24/7✡️9711147426✡️ Escorts Service
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 

Database Project

  • 1. Database Systems Introduction to Databases and Data Warehouses (Solutions to mini cases: MC1, MC2, MC3, MC4, MC6, MC7 )
  • 2. MC1 Investco Scout Investco Scout is an investment research company. Create the ER diagram for the Investco Scout Funds Database, based on the following requirements. • The Investco Scout Funds Database will keep track of investment companies, the mutual funds they manage, and securities contained in the mutual funds. • For each investment company, Investco Scout will keep track of a unique investment company identifier and a unique investment company name as well as the names of multiple locations of the investment company. • For each mutual fund, Investco Scout will keep track of a unique mutual fund identifier as well as the mutual fund name and inception date.
  • 3. • For each security, Investco Scout will keep track of a unique security identifier as well as security name and type. • Investment companies can manage multiple mutual funds. Investco Scout does not keep track of investment companies that do not manage any mutual funds. A mutual fund is managed by one investment company. • A mutual fund contains one or many securities. A security can be included in many mutual funds. Investco Scout keeps track of securities that are not included in any mutual funds. • For each instance of a security included in a mutual fund, Investco Scout keeps track of the amount included.
  • 4. MC1 Investco Scout Funds: ER Diagram
  • 5. MC1 Investco Scout Funds: Relational Schema
  • 6. Additions to the initial requirements • Investco Scout will keep track of the CEOFName and CEOLName for each investment company (in addition to keeping track of a unique investment company identifier, a unique investment company name, and names of multiple locations of the investment company for each investment company).
  • 7. CREATE TABLE statements: CREATE DATABASE IF NOT EXISTS MC1_Investco_Funds; USE MC1_Investco_Funds; CREATE TABLE COMPANY ( CompID CHAR(3) NOT NULL, CompName VARCHAR(45) NOT NULL, CEOFname VARCHAR(25) NOT NULL, CEOLname VARCHAR(25) NOT NULL, PRIMARY KEY (CompID), UNIQUE (CompName)); CREATE TABLE COMPANY_LocationName ( LocationName VARCHAR(25) NOT NULL, CompID CHAR(3) NOT NULL, PRIMARY KEY (LocationName , CompID), FOREIGN KEY (CompID) REFERENCES COMPANY (CompID));
  • 8. CREATE TABLE FUND ( FundID CHAR(2) NOT NULL, FundName VARCHAR(25) NOT NULL, InceptionDate DATE NOT NULL, Mix VARCHAR(128) NOT NULL, CompID CHAR(3) NOT NULL, PRIMARY KEY (FundID), FOREIGN KEY (CompID) REFERENCES COMPANY (CompID)); CREATE TABLE SECURITY ( SecurityID CHAR(3) NOT NULL, SecName VARCHAR(25) NOT NULL, SecType VARCHAR(25) NOT NULL, PRIMARY KEY (SecurityID)); CREATE TABLE Contain ( Amount NUMERIC(7 , 2 ) NOT NULL, FundID CHAR(2) NOT NULL, SecurityID CHAR(3) NOT NULL, PRIMARY KEY (FundID , SecurityID), FOREIGN KEY (FundID) REFERENCES FUND (FundID), FOREIGN KEY (SecurityID) REFERENCES SECURITY (SecurityID));
  • 9. INSERT INTO statements: INSERT INTO COMPANY VALUES ('ACF','Acme Finance','Mick','Dempsey'); INSERT INTO COMPANY VALUES ('TCA','Tara Capital','Ava','Newton'); INSERT INTO COMAPANY VALUES ('ALB','Albritton','Lena','Dollar'); INSERT INTO COMPANY_LocationName VALUES('Chicago','ACF'); INSERT INTO COMPANY_LocationName VALUES('Denver','ACF'); INSERT INTO COMPANY_LocationName VALUES('Houston','TCA'); INSERT INTO COMPANY_LocationName VALUES('New York City','TCA'); INSERT INTO COMPANY_LocationName VALUES('Atlanta','ALB'); INSERT INTO COMPANY_LocationName VALUES('New York City','ALB'); INSERT INTO SECURITY VALUES ('AE','Abhi Engineering','Stock'); INSERT INTO SECURITY VALUES ('BH','Blues Health','Stock');
  • 10. INSERT INTO SECURITY VALUES ('CM', 'County Municipality', 'Bond'); INSERT INTO SECURITY VALUES ('DU', 'Downtown Utility','Bond'); INSERT INTO SECURITY VALUES ('EM', 'Emmitt Machines','Stock'); INSERT INTO FUND(CompID, InceptionDate, FundID, FundName, Mix) VALUES ('ACF', '2005-1-1', 'BG', 'Big Growth', '500 AE Stocks, 300 EM Stocks'); INSERT INTO FUND(CompID, InceptionDate, FundID, FundName, Mix) VALUES ('ACF', '2006-1-1','SG','Steady Growth', '300 AE Stocks, 300 DU Bonds'); INSERT INTO FUND VALUES ('LF', 'Tiger Fund', '2005-1-1','TCA', '1000 EM Stocks, 1000 BH Stocks'); INSERT INTO FUND VALUES ('OF', 'Owl Fund', '2006-1-1','TCA', '1000 CU Bonds, 1000 DU Bonds'); INSERT INTO FUND VALUES ('JU', 'Jupiter', '2005-1-1','ALB', '2000 EM Stock, 1000 DU Bonds'); INSERT INTO FUND VALUES ('SA', 'Saturn', '2006-1-1','ALB', '1000 EM Stock, 2000 DU Bonds');
  • 11. MC1 Investco Scout Funds in MySQL Workbench
  • 12. MC2 Funky Bizz MC2 Funky Bizz Funky Bizz is a rental business that rents musical instruments to bands. Create the ER diagram for the Funky Bizz Operations Database, based on the following requirements. • The Funky Bizz Operations Database will keep track of instruments, bands, repair technicians, and shows. For each instrument, Funky will keep track of a unique instrument serial number as well as the instrument model and brand the year when the instrument was made, and the age (measured in years) of the instrument. • The customers of Funky Bizz are bands. For each band, Funky Bizz will keep track of the unique band name and unique band identifier as well as the band's address, contact person's name, and multiple phone numbers.
  • 13. • Repair technicians maintain the instruments. For each technician, Funky Bizz will keep track of a unique SSN as well as a name, ad dress, and multiple phone numbers. • Funky Bizz will record information about shows that its customer bands perform in. For each show, it will keep track of a unique show identifier composed of the show venue name and date. • For each show it will also keep track of show type and show name (a show may or may not have a name) • A band does not have to rent any instruments, but may rent up to 30. Each instrument may be rented by one band or by no bands at all • A repair technician may repair many or no instruments, and an instrument may be repaired by many or no technicians • A band may perform in many shows, but does not have to perform in any. Each show must have at least one band performing, but may have many bands performing • For each band, Funky Bizz keeps track of the number of shows that each band performs in.
  • 14. MC2 Funky Bizz Operations: ER Diagram
  • 15. MC2 Funky Bizz Operations: Relational Schema * Each band may rent up to 30 instruments
  • 16. CREATE TABLE Statements: CREATE TABLE SHOWS ( Venue VARCHAR(25) NOT NULL, Date DATE NOT NULL, Type VARCHAR(25) NOT NULL, Name VARCHAR(128), PRIMARY KEY (Venue , Date)); CREATE TABLE BAND ( BandName VARCHAR(25) NOT NULL, BandID CHAR(3) NOT NULL, Address VARCHAR(128) NOT NULL, ContactName VARCHAR(25) NOT NULL, PRIMARY KEY (BandID), UNIQUE (BandName)); CREATE TABLE BAND_PhoneNo ( PhoneNo VARCHAR(15) NOT NULL, BandID CHAR(3) NOT NULL, PRIMARY KEY (PhoneNo , BandID), FOREIGN KEY (BandID) REFERENCES BAND (BandID)); CREATE TABLE Performs ( BandID CHAR(3) NOT NULL, Venue VARCHAR(25) NOT NULL, Date DATE NOT NULL, PRIMARY KEY (BandID , Venue , Date), FOREIGN KEY (BandID) REFERENCES BAND (BandID), FOREIGN KEY (Venue , Date) REFERENCES SHOWS (Venue , Date));
  • 17. CREATE TABLE INSTRUMENT ( InstrumentSN VARCHAR(128) NOT NULL, Model VARCHAR(25) NOT NULL, Brand VARCHAR(25) NOT NULL, Year INT NOT NULL, BandID CHAR(3), PRIMARY KEY (InstrumentSN), FOREIGN KEY (BandID) REFERENCES BAND (BandID)); CREATE TABLE REPAIRTECH ( RTSSN INT NOT NULL, RTName INT NOT NULL, RTAddress INT NOT NULL, PRIMARY KEY (RTSSN)); CREATE TABLE REPAIRTECH_PhoneNo ( RTPhoneNo INT NOT NULL, RTSSN INT NOT NULL, PRIMARY KEY (RTPhoneNo , RTSSN), FOREIGN KEY (RTSSN) REFERENCES REPAIRTECH (RTSSN)); CREATE TABLE Repairs ( InstrumentSN VARCHAR(128) NOT NULL, RTSSN INT NOT NULL, PRIMARY KEY (InstrumentSN , RTSSN), FOREIGN KEY (InstrumentSN) REFERENCES INSTRUMENT (InstrumentSN), FOREIGN KEY (RTSSN) REFERENCES REPAIRTECH (RTSSN));
  • 18. BEFORE INSERT / UPDATE Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC2_Funky_Bizz`.`INSTRUMENT_BEFORE_INSERT` BEFORE INSERT ON `INSTRUMENT` FOR EACH ROW BEGIN DECLARE totalinstruments INT DEFAULT 0; SELECT count(InstrumentSN) INTO totalinstruments FROM INSTRUMENT WHERE BandID = NEW.BandID; IF (totalinstruments>=30) THEN SET NEW.BandID = NULL; SET NEW.InstrumentSN = NULL; END IF; END;
  • 19. MC2 Funky Bizz Operations in MySQL Workbench
  • 20. MC3 Snooty Fashions Snooty Fashions is an exclusive custom fashion designer business. Create the ER diagram for the snooty Fashions Database based on the following requirements . The Fashions Operations Operations Database will keep track of the following: • SSN as For each designer: a unique designer identifier and unique well as the name (composed of first and last name) • For each customer: a unique customer's identifier as well as his or her name and multiple phone numbers. • For each tailoring technician: a unique SSN as well as his or her name (composed of and last name) • For each outfit: a unique outfit's identifier as well as the outfit's planned date of completion and its unreasonable price
  • 21. • For each fashion show: a unique show identifier as well as the date of the show and location • Each designer designs many outfits. • Each outfit has only one designer. Each outfit is sold (in advance) to exactly one customer. Customers can buy one or many outfits (snooty Fashions will not keep track of customers that have not made any purchases yet) • Each tailoring technician must work on at least one outfit but can work on many. Each outfit has at least one tailoring technician working on it but can have many snooty Fashions will keep track of the date when a tailoring technician started working on a particular outfit • Each designer can participate in a number of fashion shows, but does not have to participate in any. Each fashion show can feature one or two Snooty Fashions designers (Snooty Fashions will not keep track of fashion shows that do not feature Snooty Fashions designers).
  • 23. MC3 Fashions Operations: Relational Schema *Each fashion show can feature one or two designers
  • 24. CREATE TABLE Statements: CREATE DATABASE IF NOT EXISTS MC3_Fashions_Operations; USE MC3_Fashions_Operations; CREATE TABLE IF NOT EXISTS DESIGNER ( DesignerID CHAR(3) NOT NULL, DesSSN CHAR(9) NOT NULL, DesFName VARCHAR(25) NOT NULL, DesLName VARCHAR(25) NOT NULL, PRIMARY KEY (DesignerID), UNIQUE (DesSSN)); CREATE TABLE IF NOT EXISTS FASHIONSHOW ( ShowID CHAR(3) NOT NULL, Date DATE NOT NULL, Location VARCHAR(45) NOT NULL, PRIMARY KEY (ShowID)); CREATE TABLE IF NOT EXISTS Participates ( DesignerID CHAR(3) NOT NULL, ShowID CHAR(3) NOT NULL, PRIMARY KEY (DesignerID , ShowID), FOREIGN KEY (DesignerID) REFERENCES DESIGNER (DesignerID), FOREIGN KEY (ShowID) REFERENCES FASHIONSHOW (ShowID));
  • 25. CREATE TABLE IF NOT EXISTS CUSTOMER ( CustID VARCHAR(3) NOT NULL, CustName VARCHAR(45) NOT NULL, PRIMARY KEY (CustID));CREATE TABLE IF NOT EXISTS CUSTOMER_PhoneNo ( PhoneNo VARCHAR(15) NOT NULL, CustID VARCHAR(3) NOT NULL, PRIMARY KEY (PhoneNo , CustID), FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID)); CREATE TABLE IF NOT EXISTS OUTFIT ( OutfitID CHAR(10) NOT NULL, DateOfCompletion DATE NOT NULL, Price NUMERIC(7 , 2 ) NOT NULL, DesignerID CHAR(3) NOT NULL, CustID VARCHAR(3) NOT NULL, PRIMARY KEY (OutfitID), FOREIGN KEY (DesignerID) REFERENCES DESIGNER (DesignerID), FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID)); CREATE TABLE IF NOT EXISTS TECHNITIAN ( TailorSSN CHAR(9) NOT NULL, TechLName VARCHAR(25) NOT NULL, TechFName VARCHAR(25) NOT NULL, PRIMARY KEY (TailorSSN)); CREATE TABLE IF NOT EXISTS WorksOn ( StartDate DATE NOT NULL, TailorSSN CHAR(9) NOT NULL, OutfitID CHAR(10) NOT NULL, PRIMARY KEY (TailorSSN , OutfitID), FOREIGN KEY (TailorSSN) REFERENCES TECHNITIAN (TailorSSN), FOREIGN KEY (OutfitID) REFERENCES OUTFIT (OutfitID));
  • 26. BEFORE INSERT Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC3_Fashions_Operations`.`Participates_BEFORE_INSERT` BEFORE INSERT ON `Participates` FOR EACH ROW BEGIN DECLARE totaldesigners INT DEFAULT 0 ; SELECT COUNT(*) INTO totaldesigners FROM Participates WHERE ShowID = NEW.ShowID; IF (totaldesigners>=2) THEN SET NEW.ShowID = NULL; SET NEW.DesignerID = NULL; END IF; END;
  • 27. BEFORE UPDATE Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC3_Fashions_Operations`.`Participates_BEFORE_UPDATE` BEFORE UPDATE ON `Participates` FOR EACH ROW BEGIN DECLARE totaldesigners INT DEFAULT 0; SELECT COUNT(*) INTO totaldesigners FROM Participates WHERE ShowID = NEW.ShowID; IF (totaldesigners>=2) THEN SET NEW.ShowID = NULL; SET NEW.DesignerID = NULL; END IF; END;
  • 28. MC3 Fashions Operations in MySQL Workbench
  • 29. MC4 Signum Libri Signum Libri (SL) is a publishing company. Create the ER diagram for the SL Operations Database based on the following requirements. SL operations Database will keep track of the following: • For each book SL publishes: a book name, genre, date of publication and number of pages • For each writer: a unique writer identifier as well as the writer's name • For each agent: a unique agent identifier as well as the agent's name • For each editor: a unique editor identifier as well as the editor's name. • Each SL book is written by one writer, and each writer can write many SL books. SL will not keep track of writers who did not write a book for SL. All books written by the same writer have a different book name. However, two writers can write two different books with the same book name. • Each writer is represented by one agent. Each agent represents at least one writer, but can represent many. • Each book has one editor. Each editor edits at least book, but can one edit many books. • Each editor can mentor one or more other not have editors, but does to mentor any. Each editor can have at most one mentor editor, but does not have to have any.
  • 30. MC4 SL Operations: ER Diagram
  • 31. MC4 SL Operations: Relational Schema * Each editor can have at most one mentor editor
  • 32. CREATE TABLE statements: CREATE TABLE AGENT ( AgentID VARCHAR(11) NOT NULL, AgentName VARCHAR(25) NOT NULL, PRIMARY KEY (AgentID)); CREATE TABLE WRITER ( WriterID VARCHAR(11) NOT NULL, WriterName VARCHAR(25) NOT NULL, AgentID VARCHAR(11) NOT NULL, PRIMARY KEY (WriterID), FOREIGN KEY (AgentID) REFERENCES AGENT (AgentID)); CREATE TABLE EDITOR ( EditorID VARCHAR(11) NOT NULL, EditorName VARCHAR(25) NOT NULL, Mentors_EditorID VARCHAR(11) NULL, PRIMARY KEY (EditorID), FOREIGN KEY (Mentors_EditorID) REFERENCES EDITOR (EditorID)); CREATE TABLE BOOK ( BookName VARCHAR(45) NOT NULL, Genre VARCHAR(25) NOT NULL, DateOfPublication DATE NOT NULL, NoOfPages INT(11) NOT NULL, WriterID VARCHAR(11) NOT NULL, EditorID VARCHAR(11) NOT NULL, PRIMARY KEY (WriterID, BookName), FOREIGN KEY (WriterID) REFERENCES WRITER (WriterID), FOREIGN KEY (EditorID) REFERENCES EDITOR (EditorID));
  • 33. INSERT INTO statements INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG1', 'Genady'); INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG2', 'Lola'); INSERT INTO AGENT (AgentID, AgentName) VALUES ('AG3', 'Jose'); INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR1', 'Pascual Lorca', 'AG1'); INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR2', 'Miguel Topaz', 'AG1'); INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR3', 'Jannet Jane', 'AG2'); INSERT INTO WRITER (WriterID, WriterName, AgentID) VALUES ('WR4', 'Juan Martines', 'AG3');
  • 34. INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED81', 'Julian', NULL); INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED82', 'Marsha', 'ED81'); INSERT INTO EDITOR (EditorID, EditorName, Mentors_EditorID) VALUES ('ED83', 'John', NULL); INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID, EditorID) VALUES ('Jorney to it', 'Scince', '2013-01-01', 279, 'WR1', 'ED81'); INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID, EditorID) VALUES ('Having Done', 'Fantazy', '2014-03-04', 670, 'WR1', 'ED82'); INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID, EditorID) VALUES ('Upheval', 'Drama', '2015-02-05', 350, 'WR2', 'ED83'); INSERT INTO BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID, EditorID) VALUES ('Upheval', 'Comedy', '2010-08-08', 400, 'WR3', 'ED83');
  • 35. MC4 SL Operations in MySQL Workbench
  • 36. BEFORE INSERT Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC4_Libri_Operations`.`EDITOR_BEFORE_INSERT` BEFORE INSERT ON `EDITOR` FOR EACH ROW BEGIN DECLARE totalmentors INT DEFAULT 0 ; SELECT count(*) INTO totalmentors FROM EDITOR WHERE Mentors_EditorID = NEW.Mentors_EditorID; IF (totalmentors>=1) THEN SET NEW.EditorID = NULL; SET NEW.Mentors_EditorID = NULL; END IF; END;
  • 37. BEFORE UPDATE Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC4_Libri_Operations`.`EDITOR_BEFORE_UPDATE` BEFORE UPDATE ON `EDITOR` FOR EACH ROW BEGIN DECLARE totalmentors INT DEFAULT 0 ; SELECT count(*) INTO totalmentors FROM EDITOR WHERE Mentors_EditorID = NEW.Mentors_EditorID; IF (totalmentors>=1) THEN SET NEW.EditorID = NULL; SET NEW.Mentors_EditorID = NULL; END IF; END;
  • 38. MC6 Jones Dozers Jones Dozers is a construction equipment company. • Map the ER diagram for the Jones Dozers Sales and Rentals Database into a relational schema.
  • 39. MC6 JD Sales and Rentals: ER Diagram
  • 40. MC6_JD Sales_Rentals: Relational Schema * Each sales representative can be a protégé to maximum 1, and can mentor up to 3 other representatives
  • 42. MC6 Jones Dozers Data Warehouse Jones Dozers wants to create an analytical database to analyze its sales and rentals revenue. The only available data source is the Jones Sales and Rentals Database (depicted by the ER diagram and the relational schema presented above. Create a dimensional model for a data warehouse that enables analysis of sales and rentals revenue by: • date type of revenue (sale or rental) • customer • equipment • sales rep. Each row in the fact table will represent the monetary amount of revenue taken in during one sale or rental transaction.
  • 43. MC6 JD Sales Rentals: Star Schema
  • 44. MC6 Star Schema in MySQL Workbench
  • 45. BEFORE UPDATE / INSERT Trigger CREATE DEFINER = CURRENT_USER TRIGGER `JD_Sales_Rentals`.`SALESREP_BEFORE_INSERT` BEFORE INSERT ON `SALESREP` FOR EACH ROW BEGIN DECLARE totalproteges, totalmentors INT DEFAULT 0; SET totalproteges = (SELECT count(Mentors_SRepID) FROM JD_Sales_Rentals.SALESREP WHERE SRepID = NEW.SRepID); SELECT count(SRepID) FROM JD_Sales_Rentals.SALESREP WHERE Mentors_SRepID = NEW.Mentors_SRepID INTO totalmentors; IF (totalproteges>=3 OR totalmentors >=1) THEN SET NEW.SRepID = NULL; END IF; END;
  • 46. ETL INSERT INTO Statements INSERT INTO JD_SR_Dimensional.CALENDAR (FullDate, DayOfWeek, DayOfMonth, MONTH, Quarter, YEAR)SELECT DISTINCT Date AS FullDate, DAYOFWEEK(Date) AS DayOfWeek, dayofmonth(Date) AS DayOfMonth, month(Date) AS MONTH, quarter(Date) AS Qtr, year(Date) AS YEAR FROM JD_Sales_Rentals.RENTAL UNION SELECT DISTINCT Date AS FullDate, DAYOFWEEK(Date) AS DayOfWeek, dayofmonth(Date) AS DayOfMonth, month(Date) AS MONTH, quarter(Date) AS Qtr, year(Date) AS YEAR FROM JD_Sales_Rentals.SALE; INSERT INTO JD_SR_Dimensional.CUSTOMER (CustID, CustName, CustCategory) SELECT *FROM JD_Sales_Rentals.CUSTOMER; INSERT INTO JD_SR_Dimensional.EQUIPMENT (SerialNo, LastInspectDate, DateMade, Make, Type, Model) SELECT E.SerialNo, E.LastInspectDate, E.DateMade, ED.Make, ED.Type, ED.Model FROM JD_Sales_Rentals.EQUIPMENT E, JD_Sales_Rentals.EQUIPMENTDETAIL ED WHERE E.EquipDetailID = ED.EquipDetailID; INSERT INTO JD_SR_Dimensional.REVTYPE (RevType) VALUES ('rental'), ('sale');
  • 47. INSERT INTO JD_SR_Dimensional.SALESREP (SRepID, SRepFName, SRepLName, Rank, NoOfProteges, NoOfMentors)SELECT t1.SRepID, t1.SRepFName, t1.SRepLName, t1.Rank, count(t1.Mentors_SRepID) as NoOfProteges, count(t2.SRepID) as NoOfMentors FROM JD_Sales_Rentals.SALESREP t1 LEFT JOIN JD_Sales_Rentals.SALESREP t2 ON t1.SRepID=t2.Mentors_SRepIdGROUP BY SRepID; INSERT INTO JD_SR_Dimensional.FACT (CalendarKey, RevTypeKey, CustomerKey, EquipmentKey, SRepKey, TID, RevenueAmount) SELECT C.CalendarKey, RT.RevTypeKey, CU.CustomerKey, EQ.EquipmentKey, SR.SRepKey, R.RentTransID, R.Price FROM JD_SR_Dimensional.CALENDAR AS C, JD_SR_Dimensional.REVTYPE AS RT, JD_SR_Dimensional.CUSTOMER AS CU, JD_SR_Dimensional.EQUIPMENT AS EQ, JD_SR_Dimensional.SALESREP AS SR, JD_Sales_Rentals.RENTAL AS R WHERE R.Date = C.FullDate AND RT.RevType = 'rental' AND R.CustID = CU.CustID AND R.SerialNo = EQ.SerialNo AND R.SRepID = SR.SRepID UNION SELECT C.CalendarKey, RT.RevTypeKey, CU.CustomerKey, EQ.EquipmentKey, SR.SRepKey, S.SaleTransID, S.Price FROM JD_SR_Dimensional.CALENDAR AS C, JD_SR_Dimensional.REVTYPE AS RT, JD_SR_Dimensional.CUSTOMER AS CU, JD_SR_Dimensional.EQUIPMENT AS EQ, JD_SR_Dimensional.SALESREP AS SR, JD_Sales_Rentals.SALE AS S WHERE S.Date = C.FullDate AND RT.RevType = 'sale' AND S.CustID = CU.CustID AND S.SerialNo = EQ.SerialNo AND S.SRepID = SR.SRepID;
  • 48. MC7 Midtown Memorial Midtown Memorial is a hospital. • Map the ER diagram for the Midtown Memorial Patients Drug Dispense Database into a relational schema.
  • 49. MC7 Patients Drug Dispense: ER Diagram
  • 50. MC7 Patients Drug Dispense: Relational Schema *
  • 51. BEFORE UPDATE / INSERT Trigger CREATE DEFINER = CURRENT_USER TRIGGER `MC7_Patients_Drug_Dispensal`.`Includes_BEFORE_INSERT` BEFORE INSERT ON `Includes` FOR EACH ROW BEGIN DECLARE t INT DEFAULT 0; SELECT count(*) into t FROM MC7_Patients_Drug_Dispensal.NotToTakeWith WHERE (DrugID_1 = NEW.DrugID AND NotTotakeWithDrugID_2 IN (SELECT DrugID FROM MC7_Patients_Drug_Dispensal.Includes WHERE DIENumber = NEW.DIENumber and PatientID = NEW.PatientID)) or (NotToTakeWithDrugID_2 = NEW.DrugID AND DrugID_1 IN (SELECT DrugID FROM MC7_Patients_Drug_Dispensal.Includes WHERE DIENumber = NEW.DIENumber and PatientID = NEW.PAtientID)); IF (t>0) THEN SET NEW.DrugID = NULL; END IF; END;
  • 52. MC7 Patients Drug Dispense in MySQL Workbench
  • 53. MC7 Midtown Memorial Data Warehouse Midtown Memorial wants to create an analytical database to analyze drug ingredient intake by their patients. The only avail- able data source is the Midtown Memorial Patients Drug Dispensal Database and the relational schema depicted above. Create a dimensional model for a data warehouse that enables analysis of ingredient intake events by: • date • time • patient • nurse • drug • ingredient. Each row in the fact table will represent the amount (calculated as: quantity x dosage) of one ingredient taken by one patient during one drug intake event.
  • 54. MC7 Drug Ingredient Intake: Star Schema
  • 55. MC7 Star Schema in MySQL Workbench
  • 56. ETL INSERT INTO Statements INSERT INTO MC7_Ingredient_Intake.CALENDAR (FullDate, DayOfWeek, DayOfMonth, Month, Qtr, YEAR)SELECT DISTINCT DIEDate AS FullDate, DAYOFWEEK(DIEDate) AS DayOfWeek, dayofmonth(DIEDate) AS DayOfMonth, month(DIEDate) AS MONTH, quarter(DIEDate) AS Qtr, year(DIEDate) AS YEAR FROM MC7_Patients_Drug_Dispensal.DRUGINTAKEEVENT; INSERT INTO MC7_Ingredient_Intake.PATIENT (PatientID, PatientLName, PatientFName, PatientGender, PatientBDate) SELECT *FROM MC7_Patients_Drug_Dispensal.PATIENT; INSERT INTO MC7_Ingredient_Intake.NURSE (NurseID, NurseName)SELECT *FROM MC7_Patients_Drug_Dispensal.NURSE; INSERT INTO MC7_Ingredient_Intake.DRUG (DrugID, DrugName, DrugCoatingType) SELECT *FROM MC7_Patients_Drug_Dispensal.DRUG; INSERT INTO MC7_Ingredient_Intake.INGREDIENT (IngID, IngName) SELECT *FROM MC7_Patients_Drug_Dispensal.INGREDIENT;
  • 57. INSERT INTO MC7_Ingredient_Intake.DRUG_INTAKE_EVENT (CalendarKey, PatientKey, NurseKey, DrugKey, IngredientKey, DIENumber, QuantityxDosage, DIETime)SELECT C.CalendarKey, P.PatientKey, N.NurseKey, D.DrugKey, I.IngredientKey, DIE.DIENumber, INC.Quantity * CON.Dosage, DIE.DIETime FROM MC7_Ingredient_Intake.CALENDAR AS C, MC7_Ingredient_Intake.PATIENT AS P, MC7_Ingredient_Intake.NURSE AS N, MC7_Ingredient_Intake.DRUG AS D, MC7_Ingredient_Intake.INGREDIENT AS I, MC7_Patients_Drug_Dispensal.DRUGINTAKEEVENT AS DIE, MC7_Patients_Drug_Dispensal.Includes AS INC, MC7_Patients_Drug_Dispensal.Contain AS CON WHERE DIE.DIEDate = C.FullDate AND DIE.PatientID = P.PatientID AND DIE.NurseID = N.NurseID AND INC.DrugID = D.DrugID AND CON.IngID = I.IngID AND CON.DrugID = INC.DrugID AND INC.DIENumber = DIE.DIENumber AND INC.PatientID = DIE.PatientID ORDER BY DIENumber, DrugKey;
  • 58. References: Jukic N., Vrbsky S., Nestorov S. “Database Systems. Introduction to Databases and Data Warehouses”. Pearson Education Inc., 2014.