Professional Documents
Culture Documents
Table of Contents
Introduction ...............................................................................................................3
Questions When Building the Database ............................................................... 4
Assumptions.............................................................................................................. 4
ER Diagram: Preliminary ..........................................................................................5
ER Diagram: Implementation ................................................................................. 6
Normalized Relations ...............................................................................................7
Referential Integrity Constraints .......................................................................... 10
Indexes ....................................................................................................................... 11
Denormalization Decisions ..................................................................................... 11
SQL Code Used to Build Database ....................................................................... 12
Defining the Database: SQL Statements ..................................................................... 12
Populating the Database with Sample Data: Insert Statements .............................. 16
Introduction
In order to provide our client MusicMash with a proper database system we incorporated multiple stages
within our design. Below is the operational view of our database by which the MusicMash employee will
view upon login. This paper will then outline the steps in order to come the proposed scenario as well as
provide insight on lessons learned throughout the project.
Assumptions
ER Diagram: Preliminary
ER Diagram: Implementation
Normalized Relations
10
L.
M.
N.
O.
P.
Indexes
Denormalization Decisions
We have decided not to denomalize any tables because all of our tables
contain useful data. We have made the minimum amount of tables required to
solve this case under our desire and we want to keep the data as crisp and
clean for the user as possible. One potential denormalization is the subscriber
and non-subscriber tables but we decided against it because subscriber has a
relationship with subscription. If we denormalized subscriber and nonsubscriber, we would have a lot of unnecessary null values. We believe we
provide a strong database that does not need to be denormalized. It is
efficient in search with the indexes and because we used so few indexes
there's no need to denormalize the tables for searchability purposes. Our
strong index design that aligns with customer needs also allows us to keep
the tables the way they are and if we denormalized those tables we may need
to get rid of some of those indexes. The current design is the most user
friendly possible because if we were MusicMash we would want these indexes
for search and because the database has common sense to it.
11
12
13
14
SReleaseDate DATE,
CONSTRAINT SONG_PK PRIMARY KEY (SongID),
CONSTRAINT SONG_FK1 FOREIGN KEY (ArtID) REFERENCES ARTIST,
CONSTRAINT SONG_FK2 FOREIGN KEY (RId) REFERENCES RECORDLABEL
);
STATION TABLE
CREATE TABLE STATION
(
StationID varchar2(5) NOT NULL,
StartType varchar2(5),
CONSTRAINT STATION_PK PRIMARY KEY (StationID)
);
STATION_SONG TABLE
CREATE TABLE STATION_SONG
(
STATSONGID VARCHAR2(10) NOT NULL,
StationID VARCHAR2(5) NOT NULL,
SongId VARCHAR2(7) NOT NULL,
CONSTRAINT STATION_SONG_PK PRIMARY KEY (STATSONGID),
CONSTRAINT STATION_SONG_FK1 FOREIGN KEY (StationId) REFERENCES
STATION,
CONSTRAINT STATION_SONG_FK2 FOREIGN KEY (SongId) REFERENCES SONG
);
SUBSCRIBER TABLE
CREATE TABLE SUBSCRIBER
(
CId VARCHAR2(10) NOT NULL,
SubselectID VARCHAR (6) NOT NULL,
CCNumber NUMBER(16),
CCExpMonth NUMBER(2),
CCExpYear NUMBER(4),
CCSecurityCode NUMBER(3),
CCPaypalOption VARCHAR2(1),
SDuration VARCHAR2(30),
SendDate DATE,
CONSTRAINT SUBSCRIBER_FK FOREIGN KEY (CId) REFERENCES CUSTOMER(CId),
CONSTRAINT SUBSCRIBER_FK2 FOREIGN KEY (SubselectId) REFERENCES
SUBSCRIPTION(SubselectId)
);
SUBSCRIPTION TABLE
CREATE TABLE SUBSCRIPTION
(
SubselectId VARCHAR2(6) NOT NULL,
SubscriptionType VARCHAR2(2),
CONSTRAINT SUBSCRIPTION_PK PRIMARY KEY (SubselectId)
);
15
Indexes
CREATE INDEX idx_MainAlg ON CUSTOMER_SONG(Songrating, Songtype,
Songratingtime, Songskiptimes);
CREATE INDEX idx_UsageFreq ON CUSTOMER_SONG(Songusagefrequency);
CREATE INDEX idx_CustomerLoyalty ON SUBSCRIBER(SDuration);
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
ACCOUNTEXEC
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('001','Pulson Records');
('002', 'Fly Records');
('003','Yo Records');
('004','Rap Records');
('005','Crash Records');
('006','Latin Records');
('007','Titan Records');
('008','Retoggle Records');
('009','Gofish Records');
('010','Bingo Records');
ALBUM TABLE
INSERT INTO ALBUM VALUES
('0000001','0000000001',20.99,'TheComeback','Rock'
);
INSERT INTO ALBUM VALUES
('0000002','0000000002',20.99,'TheReturn','Hip-Hop'
);
INSERT INTO ALBUM VALUES
('0000003','0000000003',2.99,'Love','Latin'
);
INSERT INTO ALBUM VALUES
('0000004','0000000004',0.99,'Loving','Latin'
);
INSERT INTO ALBUM VALUES
('0000005','0000000005',30.99,'Adventure','Latin'
);
INSERT INTO ALBUM VALUES
('0000006','0000000006',10.99,'Journey','Latin'
);
INSERT INTO ALBUM VALUES
('0000007','0000000007',40.99,'Baby','Pop'
);
INSERT INTO ALBUM VALUES
('0000008','0000000008',10.99,'Star','Pop'
);
INSERT INTO ALBUM VALUES
('0000009','0000000009',30.99,'Yoyo','Rap'
16
);
INSERT INTO ALBUM VALUES
('0000010','0000000010',20.99,'Comingback','Rap'
);
ARTIST
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
TABLE
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
INTO ARTIST
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('0000000001','PlusBoys');
('0000000002','Jerseyboys');
('0000000003','Princeroyce');
('0000000004','Nickyjam');
('0000000005','EnriqueInglesias');
('0000000006','Shakira');
('0000000007','JustinBieber');
('0000000008','SelenaGomez');
('0000000009','LittleJ');
('0000000010','Mr.P');
CONTACT TABLE
INSERT INTO CONTACT VALUES
('0000000001','0000000001','Email','1
INSERT INTO CONTACT VALUES
('0000000003','0000000002','Email','1
INSERT INTO CONTACT VALUES
('0000000005','0000000003','Email','1
INSERT INTO CONTACT VALUES
('0000000007','0000000004','Email','1
INSERT INTO CONTACT VALUES
('0000000009','0000000005','Email','1
INSERT INTO CONTACT VALUES
('0000000011','0000000006','Email','1
INSERT INTO CONTACT VALUES
('0000000013','0000000007','Email','1
INSERT INTO CONTACT VALUES
('0000000015','0000000008','Email','1
INSERT INTO CONTACT VALUES
('0000000017','0000000009','Email','1
INSERT INTO CONTACT VALUES
('0000000019','0000000010','Email','1
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
Week Reminder');
CUSTOMER TABLE
INSERT INTO CUSTOMER VALUES
(
'0000000001',
'NS',
'Park',
'Arizona',
'85719',
'Tucson',
'24-Nov-2015',
'24-Nov-2015 11:19:00AM',
'22-Jun-1995',
17
'FrankSinatra@gmail.com',
Frank Sinatra,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000002',
'NS',
'Broadway',
'Arizona',
'85028',
'Phoenix',
'24-Nov-2015',
'24-Nov-2015 11:19:00AM',
'22-May-1975',
'peterthiel@paypal.com',
Peter Thiel,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000003',
'NS',
'Rightfella',
'Alaska,
'30019',
'Anchorage',
'14-Jan-2015',
'14-Jan-2015 01:19:00AM',
'02-Jun-1993',
'kingkong@gmail.com',
King Kong,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000004',
'S',
'Mant',
'Florida,
'65028',
'Daytona',
'26-Nov-2015',
'26-Nov-2015 06:15:00AM',
'10-Apr-1974',
'gregl@paypal.com',
Greg Lapiner,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000005',
18
'NS',
'Trench',
'New Mexico,
'17019',
'New Mexico',
'20-Jan-2015',
'20-Jan-2015 01:19:00AM',
'15-Aug-1990',
'JustinBeebs@gmail.com',
Justin Beebs,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000006',
'S',
'Broadway',
'New York,
'10001',
'New York',
'03-Dec-2015',
'03-Dec-2015 07:19:00PM',
'03-Dec-1979',
'seanparker@napster.com',
Sean Parker,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000007',
'NS',
'Alder',
'New York',
'10701',
'Yonkers',
'07-Aug-2015',
'07-Aug-2015 03:59:00PM',
'10-July-1993',
'DerickJeter@gmail.com',
Derick Jeter,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000008',
'S',
'University Ave',
'New York',
'10003',
'New York',
19
'03-Nov-2015',
'03-Nov-2015 05:19:00PM',
'19-Mar-1982',
'Johnny@facebook.com',
Johnny Football,
F
);
INSERT INTO CUSTOMER VALUES
(
'000000009',
'NS',
'Gitwell',
'Maine,
'10621',
'Albany',
'17-Mar-2015',
'17-Mar-2015 03:59:00PM',
'10-Feb-1925',
'AbrahamLink@gmail.com',
Abraham Linkoln,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000010',
'S',
'University Ave',
'New York,
'10003',
'New York',
'03-Nov-2015',
'03-Nov-2015 05:19:00PM',
'18-Mar-1982',
'eduardosaverin@facebook.com',
Eduardo Saver,
M
);
INSERT INTO CUSTOMER VALUES
(
'0000000011',
'NS',
'Park',
'Arizona',
'85719',
'Tucson',
'07-Dec-2015',
'07-Dec-2015 09:19:00AM',
'22-May-1995',
'mattp@gmail.com',
Matt Presto,
F
);
20
21
'85719',
'Tucson',
'07-Oct-2015',
'07-Oct-2015 09:19:00AM',
20,
'22-May-1997',
'john@email.arizona.edu',
John Lam,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000016',
'S',
'Park',
'Arizona',
'85719',
'Tucson',
'09-Nov-2015',
'09-Nov-2015 09:19:00AM',
20,
'09-Sep-1995',
'johnrichardsmith@email.arizona.edu'
John Richard,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000017',
'NS',
'Park',
'Arizona',
'85719',
'Tucson',
'08-Oct-2015',
'08-Oct-2015 09:19:00AM',
'09-May-1997',
'kelsey@email.arizona.edu',
Kelsey Han,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000018',
'S',
'Park',
'Arizona',
'85719',
'Tucson',
'20-Nov-2015',
'20-Nov-2015 09:19:00AM',
'10-Sep-1995',
22
'ricardozavala@email.arizona.edu',
Ricardo Dozavala,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000019',
'NS',
'Park',
'Arizona',
'85715',
'Tucson',
'15-Oct-2015',
'15-Oct-2015 09:19:00AM',
'20-May-1997',
'brittney@email.arizona.edu',
Brittney Spears,
F
);
INSERT INTO CUSTOMER VALUES
(
'0000000020',
'S',
'Park',
'Arizona',
'85719',
'Tucson',
'20-Dec-2015',
'20-Dec-2015 09:19:00AM',
'10-Oct-1995',
'cristianoronaldo@email.arizona.edu',
Christiano Ronaldo,
F
);
CUSTOMER_SONG TABLE
INSERT INTO CUSTOMER_SONG VALUES
('0000001','0000000001','0000001','10','22-Nov-2015
04:59:00PM','Mellow',1,23,'23-Nov-2015 03:10:00PM','10-Jan-2015
06:53:00AM');
INSERT INTO CUSTOMER_SONG VALUES
('0000002','0000000002','0000002','9','18-Dec-2015
04:59:00PM','Mellow',2,57,'13-Dec-2015 10:52:00PM','11-Feb-2015
06:23:00PM');
INSERT INTO CUSTOMER_SONG VALUES
('0000003','0000000003','0000003','8','21-Jan-2015
04:59:00PM','Fast',3,683,'03-Jan-2015 05:32:00AM','12-May-2015
08:53:00AM');
INSERT INTO CUSTOMER_SONG VALUES
('0000004','0000000004','0000004','7','23-Aug-2015
23
04:59:00PM','Workout',4,1,'18-Aug-2015 08:02:00PM','13-Apr-2015
02:53:00AM');
INSERT INTO CUSTOMER_SONG VALUES
('0000005','0000000005','0000005','533','25-Jun-2015
04:59:00PM','Slowdown',5,23,'12-Jun-2015 12:02:00AM','14-Jan-2015
03:53:00PM');
INSERT INTO CUSTOMER_SONG VALUES
('0000006','0000000006','0000006','211','26-Feb-2015
04:59:00PM','Fast',6,23,'09-Feb-2015 05:02:00PM','15-Jan-2015
06:13:00AM');
INSERT INTO CUSTOMER_SONG VALUES
('0000007','0000000007','0000007','432','02-Jul-2015
04:59:00PM','Roadtrip',7,23,'11-Jul-2015 01:12:00AM','17-Jan-2015
02:53:00PM');
INSERT INTO CUSTOMER_SONG VALUES
('0000008','0000000008','0000008','18','03-Mar-2015
04:59:00PM','Relax',8,8,'28-Mar-2015 05:32:00PM','18-Mar-2015
01:53:00AM');
INSERT INTO CUSTOMER_SONG VALUES
('0000009','0000000009','0000009','8','04-May-2015
04:59:00PM','Sleepy',9,101,'26-May-2015 02:02:00AM','19-Feb-2015
02:27:00PM');
INSERT INTO CUSTOMER_SONG VALUES
('0000010','0000000010','0000010','5','05-Nov-2015
04:59:00PM','Mellow',10,23,'10-Nov-2015 02:02:00PM','20-Jan-2015
07:23:00AM');
CUSTOMER_SONGP TABLE
INTO CUSTOMER_SONGP VALUES
(
'00000000000000001',
'0000000001',
'0000001',
2.99,
'30-Jun-2015 10:30:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000002',
'0000000002',
'0000002',
1.99,
'01-NOV-2015 10:50:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000003',
'0000000003',
'0000003',
2.99,
'04-OCT-2015 09:30:00AM'
24
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000004',
'0000000004',
'0000004',
1.99,
'14-JAN-2015 04:30:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000005',
'0000000005',
'0000005',
2.99,
'25-DEC-2015 02:00:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000006',
'0000000006',
'0000006',
1.99,
'08-AUG-2015 11:30:00AM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000007',
'0000000007',
'0000007',
0.99,
'10-JUN-2015 01:30:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000008',
'0000000008',
'0000008',
0.99,
'01-MAY-2015 12:15:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000009',
'0000000009',
'0000009',
1.99,
'22-JUN-2015 08:15:00PM'
);
INSERT INTO CUSTOMER_SONGP VALUES
(
'00000000000000010',
25
'0000000010',
'0000010',
2.99,
'14-FEB-2015 07:30:00PM'
);
CUSTOMER_ALBUM TABLE
INSERT INTO CUSTOMER_ALBUM
(
'0000001',
'0000000001',
'0000001',
'05-May-2015'
);
INSERT INTO CUSTOMER_ALBUM
(
'0000002',
'0000000002',
'0000002',
'05-Dec-2016'
);
INSERT INTO CUSTOMER_ALBUM
(
'0000003',
'0000000003',
'0000003',
'05-May-2017'
);
INSERT INTO CUSTOMER_ALBUM
(
'0000004',
'0000000004',
'0000004',
'05-May-2018'
);
INSERT INTO CUSTOMER_ALBUM
(
'0000005',
'0000000005',
'0000005',
'05-May-2016'
);
INSERT INTO CUSTOMER_ALBUM
(
'0000006',
'0000000006',
'0000006',
'05-May-2017'
);
INSERT INTO CUSTOMER_ALBUM
(
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
26
'0000007',
'0000000007',
'0000007',
'05-May-2016'
);
INSERT INTO CUSTOMER_ALBUM VALUES
(
'0000008',
'0000000008',
'0000008',
'05-May-2017'
);
INSERT INTO CUSTOMER_ALBUM VALUES
(
'0000009',
'0000000009',
'0000009',
'05-May-2018'
);
INSERT INTO CUSTOMER_ALBUM VALUES
(
'0000010',
'0000000010',
'0000010',
'05-May-2017'
);
CUSTOMER_STATION TABLE
INSERT INTO CUSTOMER_STATION
(
'00001',
'0000000001',
'0000001',
'24-Nov-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00002',
'0000000002',
'0000002',
'14-Dec-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00003',
'0000000003',
'0000003',
'10-Jan-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00004',
VALUES
VALUES
VALUES
VALUES
27
'0000000004',
'0000004',
'11-Jun-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00005',
'0000000005',
'0000005',
'02-Jul-2014'
);
INSERT INTO CUSTOMER_STATION
(
'00006',
'0000000006',
'0000006',
'19-Aug-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00007',
'0000000007',
'0000007',
'30-May-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00008',
'0000000008',
'0000008',
'23-Feb-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00009',
'0000000009',
'0000009',
'13-Aug-2015'
);
INSERT INTO CUSTOMER_STATION
(
'00010',
'0000000010',
'0000010',
'18-Mar-2015'
);
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
NON_SUBSCRIBER TABLE
INSERT INTO NON_SUBSCRIBER VALUES
(
'0000000003',
28
'30Day',
'14-Jan-2015',
'14-Feb-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000005',
'30Day',
'20-Jan-2015',
'20-Feb-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000007',
'30Day',
'07-Aug-2015',
'07-Sep-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000009',
'30Day',
'17-Mar-2015',
'17-Apr-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000013',
'30Day',
'07-Nov-2015',
'07-Dec-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000011',
'30Day',
'07-Dec-2015',
'07-Jan-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000015',
'30Day',
'07-Oct-2015',
'07-Nov-2015'
);
INSERT INTO NON_SUBSCRIBER
(
'0000000017',
'30Day',
'08-Oct-2015',
'08-Nov-2015'
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
29
);
INSERT INTO NON_SUBSCRIBER VALUES
(
'0000000019',
'30Day',
'15-Oct-2015',
'15-Nov-2015'
);
RECORDLABEL
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
TABLE
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
RECORDLABEL
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('001','001','Roxxy',.07);
('002','002','City',.04);
('003','003','Dixie',.05);
('004','004','Shelton',.06);
('005','005','Dancxing',.07);
('006','006','Beijing',.08);
('007','007','Shanghai',.09);
('008','008','Barca',.01);
('009','009','Madrid',.03);
('010','010','LA',.04);
SONG TABLE
INSERT INTO SONG VALUES
('0000001','0000000001','001','Flying','Rock','Plus Boys','14-Oct1961');
INSERT INTO SONG VALUES
('0000002','0000000002','002','Camping','Latin','Jersey Boys','10-Feb1962');
INSERT INTO SONG VALUES
('0000003','0000000003','003','Hiking','Rock','Princeroyce','18-Jan1963');
INSERT INTO SONG VALUES
('0000004','0000000004','004','Sleeping','Rock','Nickyjam','05-Mar1964');
INSERT INTO SONG VALUES
('0000005','0000000005','005','Crying','Rock','EnriqueInglesias','12Apr-1965');
INSERT INTO SONG VALUES
('0000006','0000000006','006','Jumping','Rock','Shakira','22-May1966');
INSERT INTO SONG VALUES
('0000007','0000000007','007','Falling','Rock','JustinBieber','25-Jun1967');
INSERT INTO SONG VALUES
('0000008','0000000008','008','Laughing','Rock','SelenaGomez','30-Jul1968');
INSERT INTO SONG VALUES
('0000009','0000000009','009','Coding','Rock','LittleJ','11-Aug1969');
INSERT INTO SONG VALUES
('0000010','0000000010','010','Sitting','Rock','Mr.P','09-Sep-2015');
30
STATION TABLE
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
INSERT INTO STATION
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('00001','00001');
('00002','00002');
('00003','00003');
('00004','00004');
('00005','00005');
('00006','00006');
('00007','00007');
('00008','00008');
('00009','00009');
('00010','00010');
STATION_SONG TABLE
INSERT INTO STATION_SONG VALUES
('0000000001','00001','0000001'
);
INSERT INTO STATION_SONG VALUES
('0000000002','00002','0000002'
);
INSERT INTO STATION_SONG VALUES
('0000000003','00003','0000003'
);
INSERT INTO STATION_SONG VALUES
('0000000004','00004','0000004'
);
INSERT INTO STATION_SONG VALUES
('0000000005','00005','0000005'
);
INSERT INTO STATION_SONG VALUES
('0000000006','00006','0000006'
);
INSERT INTO STATION_SONG VALUES
('0000000007','00007','0000007'
);
INSERT INTO STATION_SONG VALUES
('0000000008','00008','0000008'
);
INSERT INTO STATION_SONG VALUES
('0000000009','00009','0000009'
);
INSERT INTO STATION_SONG VALUES
('0000000010','00010','0000010'
);
SUBSCRIBER TABLE
INSERT INTO SUBSCRIBER VALUES
(
'0000000002',
'000001',
1234123412341234,
31
12,2016,123,
'N',
'1MONTH',
'24-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000004',
'000002',
8843147296055194,
09,2017,492,
'N',
'1MONTH',
'18-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000006',
'000003',
0752117991236829,
09,2017,422,
'N',
'1MONTH',
'03-Jan-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000008',
'000004',
0752132991236829,
03,2015,422,
'N',
'TRIAL',
'20-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000010',
'000005',
0752117211236829,
09,2015,422,
'N',
'1MONTH',
'03-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000012',
'000006',
0752117992336829,
05,2017,422,
'N',
VALUES
VALUES
VALUES
VALUES
VALUES
32
'1MONTH',
'07-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000014',
'000007',
0752123991236829,
09,2015,414,
'N',
'1MONTH',
'15-Dec-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000016',
'000008',
0752117991236829,
09,2017,422,
'N',
'Bi-yearly',
'03-Jan-2015'
);
INSERT INTO SUBSCRIBER
(
'0000000018',
'000009',
1234567899876543,
09,2017,422,
'N',
'3Year',
'20-Nov-2018'
);
INSERT INTO SUBSCRIBER
(
'0000000020',
'000010',
1234567899876543,
09,2017,422,
'N',
'1Year',
'20-Dec-2016'
);
VALUES
VALUES
VALUES
VALUES
SUBSCRIPTION TABLE
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
INSERT INTO SUBSCRIPTION
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
(000001,'M');
(000002,'M');
(000003,'M');
(000004,'M');
('000005','M');
('000006','M');
('000007','M');
33
34
This is the implementation model after it has already been created in the database management system.
This is different from the ER Diagram as can be referenced above because it only contains the many to
many relationships with the relations having their own attributes on the parent side.
Table: Customer_Song
CUSTSONG_ID= The identification number assigned to each customer song
interaction.
CID= The identification number assigned to each customer.
SONGID= The identification number of each song.
SONGRATING= The rating that the customers gave to the song.
SONGRATINGTIME= The time that the customer rated the song.
SONGTYPE= The type of song that the song is categorized as.
SONGSKIPTIMES= The amount of times that the song was skipped.
SONGUSAGEFREQUENCY= The frequency that the song was played.
LISTENINGTIME= The time that the customer listened to the song.
SKIPTIMEDATE= The time that the customer skipped the song.
Table: Customer_SongP
CSP_ID= The id number assigned to each song that is purchased by a
customer.
CID= The identification number assigned to each customer.
SONGID= The identification number of each song.
SONG_PRICE= The price of the individual song.
PURCHASETIME= The time that each song is purchased.
Table: Customer_Station
CUSTSTAT_ID= The id number assigned to each station listened to by a
customer.
CID= The identification number assigned to each customer.
ALBID= The identification number assigned to each album.
STATIONCREATIONTIME= The time that the station was created.
Table: Non_Subscriber
CID= The identification number assigned to each customer.
NSDURATION= The length of time that the trial lasts.
NSTARTDATE= The date that the trial was started.
NSENDATE= The date that the trial ends.
Table: Record Label
RID= The identification number assigned to the record label.
EID= The identification number assigned to the executive.
RECNAME= The name of the record.
PROFITRATIO= The profit ratio awarded to the record label.
Table: Song
SONGID= The identification number of each song.
ARTID= The identification number assigned to each artist.
RID= The identification number assigned to the record label.
37
38
Queries
In order to extract the data that was requested by MusicMash, the following
statements were crafted and subsequently ran. These statements are vital for
contributing to a MusicMash employees daily needs.
1. Most popular songs in a given month/year
SELECT Song.SongID,
Song.Sname,
Customer_Song.SONGUSAGEFRequency
FROM Song,
Customer_Song
WHERE Song.SongID=Customer_Song.SongID
AND Song.SongID IN
(SELECT SongID
FROM
(SELECT SONGID ,
SONGUSAGEFRequency ,
rank() over (order by SONGUSAGEFRequency DESC) AS rnk
FROM Customer_SONG
)
WHERE rnk <= 10
);
AND extract(MONTH FROM ListeningTime) =
&ListeningMonth
AND extract(YEAR FROM ListeningTime) =
&ListeningYear;
2. Most popular artists in a given month/year
SELECT Artist.ArtID,Artist.Artname,
Customer_Song.SONGUSAGEFRequency
FROM Song,
Customer_Song, Artist
WHERE Song.SongID=Customer_Song.SongID AND Song.ArtID =
Artist.ArtID
AND Song.SongID IN
(SELECT SongID
FROM
(SELECT SONGID ,
SONGUSAGEFRequency ,
rank() over (order by SONGUSAGEFRequency DESC) AS rnk
FROM Customer_SONG
)
WHERE rnk <= 10
39
)
AND extract(MONTH FROM ListeningTime) =
&ListeningMonth
AND extract(YEAR FROM ListeningTime) =
&ListeningYear;
3. Songs that are skipped most often by customers
SELECT SongID, SongSkiptimes
FROM
(SELECT SONGID ,
songskiptimes ,
rank() over (order by Songskiptimes DESC) AS rnk
FROM Customer_SONG
)
WHERE rnk <= &Howmanysongs;
4. Number of days until a trial expires for each trial customer
SELECT CID, SDuration, Round(senddate-sysdate) as
Numberofdaystillexpiration
FROM dual, subscriber
WHERE SDuration = 'TRIAL' AND Round(senddate-sysdate) >= 0;
5. An ordered list of the number of days until a subscription expires for paying
customers except monthly customers
SELECT CID, SDuration, Round(senddate-sysdate) as
Numberofdaystillexpiration
FROM dual, subscriber
WHERE SDuration <> 'TRIAL' AND SDuration <> '1MONTH' AND
Round(senddate-sysdate) >= 0
ORDER BY Numberofdaystillexpiration DESC;
6. Most popular categories of music by gender of the customer
SELECT Customer.Cgender, Customer_Song.songtype,
count(Customer_Song.songtype) as Most_Popular
FROM Customer, Customer_Song
WHERE Customer.CID = Customer_Song.CID AND Cgender = &Gender
GROUP BY Customer.Cgender, Customer_Song.songtype
ORDER BY count(Customer_Song.songtype) DESC;
7. Most popular song by region of the country
40
41
42
Run this query with the respective SQL code, listed above. Running the
aforementioned query will return the number of days until the trail expiries for
each trial customer. By include our WHERE statement, we have prevented
issues that may result from legacy data interfering with the current data in the
query. This also allows you to keep the legacy data in the database without
taking away from the queries you need to run for your business operation.
5. An ordered list of the number of days until a subscription expires for paying
customers except monthly customers
Run this query with the respective SQL code, listed above. Running the
aforementioned query will return an ordered list of the number of the days
until a subscription expires for paying customers except monthly customers.
By include our WHERE statement, we have prevented issues that may result
from legacy data interfering with the current data in the query. This also
allows you to keep the legacy data in the database without taking away from
the queries you need to run for your business operation.
6. Most popular categories of music by gender of the customer
Run this query with the respective SQL code, listed above. The query will
prompt you to (1) Enter Value for Gender, where Gender is defined as M, male,
or F, female. Be sure to when inputting male or female in quotes: M or F. A
common mistake is using double quotes (i.e. M or F) when inputting the
value. Running the aforementioned query will return the categories of music
by gender.
7. Most popular song by region of the country
Run this query with the respective SQL code, listed above. The query will
prompt you to (1) Enter Value for Region, where Region is defined as W,
West, N, North, E, East, S, South, NE, Northeast, NW, Northwest, SE,
Southeast, and SW, Southwest. The aforementioned query will return the
most popular song in your specified region of the country.
8. Monthly payments to record labels for purchased songs/albums.
Run this query with the respective SQL code, listed above. The query will
prompt you to (1) Enter value for PurchaseSongMonth, where
PurchaseSongMonth is the month in which the customer purchased the song
and (2) Enter value for PurchaseAlbumMonth, where PurchaseAlbmMonth is
the month in which the cusomter purchased the album. The values that you
are entering isolate your calculation for that specific month, allowing you to
find the monthly payment for songs or albums for that specific month.
44
Running the aforementioned query will return the monthly payments for
purchased songs and albums.
9. Monthly payment to account executives each month.
Run this query with the respective SQL code, listed above. The query will
prompt you to (1) Enter value for PurchaseMonth, where PurchaseMonth is the
month in which the songs were purchased that the account executive will get
paid for. Running the aforementioned query will return monthly payment to
account executives each month.
10. Average price of music albums based on genre.
Run this query with the respective SQL code, listed above. Running the
aforementioned query will return average price of music albums based on
genre
11. Average number of songs each customer listens to per day.
Run this query with the respective SQL code, listed above. Running the
aforementioned query will return the average number of songs each customer
listens to in the past (+/-) 12 hours.
45
employees will take notes on what you are saying, and give them something
to reference when they use the database following the training session. Make
the handout simple, clean, and concise.
Restrict employee access to only the parts of the database each individual
employee needs to access. We dont want to grant root access to all users.
Provide further opportunities for employees to expand their skill set with
respect to the database. Hold optional advanced seminars every 3 months to
allow for employees to grow. Grant employees access to existing Webinars
and courses (i.e. Lynda.com) so they can grow their knowledge as it suits
them, at their on pace, on their own time.
Technology Issues
46
Lessons Learned
One of the most important lessons we learned over the course for the
semester while working on this project is the importance of attention to detail.
While imputing our SQL codes into the database, we encounter many errors.
A handful of these errors were caused simply because we did not pay close
enough attention when entering the sequences into the database. Forgetting
to add the semicolon after each statement and missing punctuations were
common mistakes we made at in the beginning. This was because we were
quickly entering the create table and insert statements while utilizing the
Google Docs application, where we had originally typed statements. When
copying and pasting these statements over, the formatting of them changed
as the functions in Mac OS X copy/paste function altered some of the
formatting. While we were trying to be time efficient in copying and pasting
multiple statements at a time, we actually spent more time trying to search
for where the error occurred in each line and correct the statement. Moving
forward, we learned to carefully type these statements directly into the
program to ensure we had the correct elements and formatting for each.
Once we nailed this down, we were able to efficiently enter the data.
The database itself was instrumental for learning lessons for the project. The
first lesson that SQL taught us was regarding foreign keys. A foreign key must
be added from an existing primary key in SQL. When we tried to correct this
issue by adding a second primary key, SQL will not allow it. After dropping
multiple tables and reinserting data we realized that the reason this foreign
kay could not be added was data redundancy. The data was redundant and
should have only been placed in one of our two tables. This second example
of how SQL taught us a lesson was in inserting the data. When we tried to
insert data we had to have more than 10 entries in the customer table. This is
because customers were later sub grouped into subscribers and non
subscribers. If we did not add more than 10 entries in our customer table, then
the subscriber and non subscriber tables would not have enough data per the
instructions of the assignment. This was easily rectified by the addition of 10
subscribers and 10 non subscribers in our customer table.
47