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.
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');
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.
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;
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).
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;
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.
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.
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.
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.
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;
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.
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.