GLOB Documentation - Format
GLOB Documentation - Format
TITLE OF PROJECT
By
Neelima: Gogineni
&
Sravya: Boya
Associate Professor
CERTIFICATE
This is to certify that the micro project titled “TITLE OF THE PROJECT” is a bonafide work done
by Name of the Student (Roll Number), Name of the Student (Roll Number), Name of the Student
(Roll Number) under Visual Programming Using C# and .Net Lab - GRIET Lab On Board (G-
LOB) practice of our institute and that this work has not been submitted for the award of any other
Degree/Diploma of any Institution/University.
Project Guides
Neelima: Gogineni
Sravya: Boya
Assistant Professors
1
Table of Contents
Ch. No. Chapter Name Pg. No.
1 Introduction 1
1.1. Need for the Project 1
1.2. End Users of the Project 2
2 Requirement Analysis 3
3 Conceptual Database Design 4
4 Logical Database Design
4.1. Relation Name
4.2. Relation Name
4.3. Relation Name
5 SQL Code for Creation of Database
5.1. Creation of Tables - DDL
5.2. Referential Integrity Constraints - DDL
5.3. Insert, Delete, and Update Data - DML
6 Retrieval of Data - DQL
7 Views
8 PL/SQL Code for retrieval and manipulations
8.1. Cursors
8.2. Triggers
8.3. Functions/ Procedures
9 References/ Tools Used
2
1. Introduction
This project attempts to address the requirements of Notown Records who have decided
to store information about musicians who perform on its albums (as well as other company data)
in a database. Database was developed entirely using Oracle services.
● Each musician that records at Notown has an SSN, a name, an address, and a phone
number. Poorly paid musicians often share the same address, and no address has more
than one phone.
3
● Each instrument used in songs recorded at Notown has a name (e.g., guitar, synthesizer,
flute) and a musical key (e.g., C, B-flat, E-flat).
● Each album recorded on the Notown label has a title, a copyright date, a format (e.g., CD
or MC), and an album identifier.
● Each song recorded at Notown has a title and an author.
● Each musician may play several instruments, and a given instrument may be played by
several musicians.
● Each album has a number of songs on it, but no song may appear on more than one
album.
● Each song is performed by one or more musicians, and a musician may perform a number
of songs.
● Each album has exactly one musician who acts as its producer. A musician may produce
several albums, of course.
Design a conceptual schema for Notown and draw an ER diagram for your schema. The
preceding information describes the situation that the Notown database model.
1.3. Overview
The ER Model is designed to meet the requirements of Notown Records. Based on the ER model
created, The schema is created to represent the structure of the database. The Database is created
consisting of relations (Musicians, Albums, Instruments, Songs) with the constraints and
relations as requested by the client.
1.4. Goals
1. Create a DataBase Management system for Notown Records Company to efficiently
manage their data about its music albums.
2. Creating a conceptual database design for the given problem statement
3. Create the schema with the help of conceptual design.
4. Create entities and link the relations using constraints.
5. Insert the data into the relations.
6. Retrieve the data from the relations.
4
2. Requirements Analysis
● The database is capable of storing musician details like their SSN (Social Security
Number), name, address and other basic details.
● The record company primarily deals with albums and songs distribution so the database
must be adept at storing details like album names, identifiers, contents, artists,
instruments used and its copyright time period.
● Every instrument used in songs recorded at Notown has a name and a Musical Key.
● Musicians may play several instruments, and a given instrument may be played by
several musicians.
● Each song recorded at Notown has a title and an author.
● Each album has a number of songs on it, but no song may appear on more than one
album.
● Each song is performed by one or more musicians, and a musician may perform a number
of songs.
● Each album has exactly one musician who acts as its producer. A musician may produce
several albums.
5
3. Conceptual Database Design
https://app.creately.com/d/create/?templateId=4hTQ5g1y3Yt
ER Diagram
Entities
● Musician
● Instrument
● Album
● Song
● M_address
● Musical keys
6
Attributes
● Musician
○ SSN
○ m_name
● Instrument
○ i_name
● Album
○ Album Identifier
○ Title
○ Copyright Date
○ Format
● Song
○ Author
○ Title
● M_address
○ Address
○ Phone number
● Musical_Keys
○ Keys
Relationships
● Musician Plays Instrument (Many to Many)
● Musician Lives in M_address
● Musician Produces Album (One to Many)
● Album Contains Song (One to Many)
● Song Has Keys (One to Many)
7
4. Logical Database Design
1.Identifying the strong entities
From the ER diagram musicians, addresses, songs, albums, instruments and musical_keys are
identified strong entities
2. Identifying the One to Many relationships between the entities
Although the ER diagram doesn’t have any one to one relationships in it, there are several one to
many relationships present.
To convert those one to many relationships, modify the relation in the ‘’Many” side of the
relationship and add an attribute containing the primary keys of the other relation as foreign key.
Consider this example. There is a One to Many relationship between musicians and albums and
the relationship depicts musicians produce albums.
An attribute to the Albums relation named “producer_ssn” is added which holds the primary key
of the musicians relation as foreign key.
8
3. Identifying the Many to Many relations between the entities
In the ER diagram there are two Many to Many relationships. These relations are converted to a
third relation called Junction relations. They contain primary keys from both the relations and
they are made as foreign keys referencing their respective relations.
Then for the Primary key of the resulting relation we use the combination of both the foreign
keys as the Composite Primary key.
Schema Design
The schema is created using dbdiagram.io
https://dbdiagram.io/d
Schema
9
According to the requirements of the client (Notown Records company). The DataBase needs to
be capable of storing data like
The above additional requirements have been achieved by the use of basic Integrity and
Referential constraints and allows easy access of data. The relations have been created with as
little redundancy of data and as practical as possible.
10
Of these relations, the song_artists and musician_instruments relations are Junction relations.
Junction relations are often used when there is a Many to Many relationship between two
relations. Using this junction Relationship the ease in storing and retrieving data is improved.
The performs relationship between the Musicians Relations and Songs Relations
The plays relationship between the Musicians Relations and Songs Relations
The above relationships depict many to many relationship between musicians and the songs they
perform, as well as relationship between musicians and the instruments they can play.
11
Musical keys are stored as a separate relation instead of only as an attribute in songs because key
signatures of songs are often repeating and there are only 12 major key signatures used in music
and another 12 minor forms. Almost every song is written following only one key signature and
rarely song writers use more than one key so we can assume one song contains one key.
12 A A# B C C# D D# E F F# G G#
Major
Keys
13
Here the musical key and album_identifier attributes are both foreign keys which refer to the
Musical Keys Relations and the albums Relations respectively. With the album identifier as the
foreign key we can easily retrieve the album name and its data of any song.
4.7. song_artists Relation
This is a Junction Relations and as mentioned previously Many to Many relations are stored as
separate relations or Third relations. This Relations contains song name, SSN of its performer
and its release date.
Song’s name cannot be chosen as the primary key because it is very common for songs to have
the same name. So the combination of the song's name and its artist’s SSN is taken as a
composite primary key.
Song name is a foreign key which refers to the attribute in the Songs Relations and SSN refers to
the same attribute in the Musicians Relations
4.8. musical-keys Relations
This relationship only contains the keys used in songs and it is also the primary key.
14
5. SQL Code for Creation of Database
5.1. Creating the relations – DDL
The 8 relations are created using the basic DDL CREATE command. The primary keys are
created at column level whereas the foreign key is at the Relations level. Foreign keys are given
at Relations level to provide easy modification and better readability.
musicians Relation
addresses Relation
15
instruments Relation
musician_instruments Relation
CREATE TABLE
musician_instruments (
SSN varchar(9),
i_name varchar(30),
PRIMARY KEY (SSN, i_name)
);
albums Relation
songs Relation
16
album_identifier varchar(5),
PRIMARY KEY (s_name, release_date));
song_artists Relation
musical_keys Relation
Insertion is done by deactivating the foreign key constraints or done before they are declared
because insertion and deletion with foreign key constraints activated is a tedious task. After
insertion is done we can activate them.
18
Inserting into musician_instruments Relations
insert into musician_instruments values('835732871','Piano');
insert into musician_instruments values('835732871','Harmonium');
The rows are inserted before the Foreign key constraints are activated to allow easy insertion. To
insert rows this way we need to make sure our data is consistent across the relations. Data like
names, ID numbers all must match exactly and the data is case sensitive. If this is not taken care
of, we will get an error at the time of activating the constraints.
19
6. Retrieval of Data – DQL
Below are few queries that the client might use frequently
20
poor musicians M_ADDRESS
KK Street-20
21
Producer Album
Haricharan Awara
Karthik Orange
c-106 Orange 2
c-127 Pournami 1
c-110 Raahu 1
22
Song Singer
Chilipiga Karthik
Display all the songs and the musical key they are played in
select s.s_name "Song",m.m_keys"musical_keys"
from songs s join musical_keys m
on s.m_key=m.m_keys;
Song musical_keys
Gundelona Gundelona B
Tholiprema C#m
Chitti Dm
23
M_NAME PHONE_NUMBER
Anirudh 9965432155
Haricharan 9965432155
Karthik 9634554321
7. Views
24
M_NAME
Sid sriram
Anirudh
SP Charan
Ram miryala
Anurag kulkarni
DSP
VV Prassanna
Sri krishna
25
M_NAME A_NAME
Karthik Orange
KK Aarya-2
DSP Pournami
26
M_NAME S_NAME VIEWS_STREAMS
27
DBMS_OUTPUT.PUT_LINE(c_var.m_name||' with ' ||
c_var.c || ' songs ');
v_i := v_i + 1;
EXIT WHEN c_top3_artists %NOTFOUND OR v_i>=3;
END LOOP;
CLOSE c_top3_artists;
END;
/
OUTPUT:
28
EXIT WHEN c_top5 %NOTFOUND OR v_i>=5;
END LOOP;
CLOSE c_top5;
END;
/
OUTPUT:
8.2. Functions
(Function declaration)
BEGIN
IF n1<1000000 THEN
n2 := 0;
ELSIF n1>1000000 AND n1<2000000 THEN
n2 := n1*0.2;
29
ELSE
temp := n1-2000000;
n2 := (temp * 0.4)+(2000000*0.2);
END IF;
RETURN n2;
END;
/
Note: The revenue is calculated as follows.
If a song has less than a million (1,000,000) views/streams, It gets no earnings but if a song gets
more than a million it earns 0.2 rupees per view till 2 million views. After 2 million views the
songs earn 0.4 rupees per view.
OUTPUT:
(function call):
DECLARE
cursor c_earn IS
select m.m_name, s.s_name, s.views_streams from musicians m inner join song_artists s on
s.ssn=m.ssn where m.ssn=&SSN;
temp c_earn %ROWTYPE;
tot_sal number(20):=0;
BEGIN
DBMS_OUTPUT.PUT_LINE('earnings of the artist are: ');
OPEN c_earn;
LOOP
FETCH c_earn INTO temp;
EXIT WHEN c_earn %NOTFOUND;
DBMS_OUTPUT.PUT_LINE(temp.m_name ||' earned
$'||earnings(temp.views_streams)/81.49 || ' from '||temp.s_name);
tot_sal := tot_sal + earnings(temp.views_streams);
END LOOP;
30
DBMS_OUTPUT.PUT_LINE('Total earnings are $'|| tot_sal/81.49);
CLOSE c_earn;
END;
/
OUTPUT:
8.3. Triggers
1. Trigger for updating the address of musicians
31
END IF;
END;
/
OUTPUT:
This triggers when an update operation is performed on the m_address attribute of musicians
relation.
If the updated m_address record is already present in the master relation ‘addresses’. There is no
conflict with referential integrity constraints so we face no problem.
But If the updated m_address attribute is not present in the master relation then this trigger adds
the newly updated address to addresses relation as well.
OUTPUT:
Successfully updated
32
Updating the address of a musician with an unseen address:
SQL> update musicians set m_address = 'Street-99' where ssn=123456789;
OUTPUT:
33
A new record of the updated address is added to the addresses relation by the trigger.
9. References/Tools used
35