Economics and Management
Database Systems project:
Database for Mineral Collectors
Introduction
This work designs a database that contains information about mineral collection. It intends to
capture basic information needed for collection management. It’s based on following
assumptions:
•
Each sample can contain one-to-many minerals (e.g. quartz + calcite) and comes from
•
one and exactly one locality, founder of the sample can sometimes be unknown.
Each sample can be captured on several photos, each photo in turn is taken by one
•
•
person.
Each sample can be a subject of transaction (bought/sold)
Person can be a founder or an author of photographs in this content, the entities are
•
differentiable only by their roles in relationship
Each location/person
This project does not address the problem of storage (where are the samples currently
placed), it also ignores several important attributes that would be required in real world
system.
Outline
1. Possible use cases for the model
•
•
•
•
•
•
Find specific sample based on selection criteria (locality, founder, year)
Find all the samples from locality
Find all the localities in collection where a mineral was found
Find all photos of a mineral
Get all minerals found by certain person
Get all samples purchase from certain person
2. Entity relationship diagrams
Following section captures the proposed structure of database using entity relationship
diagram. The diagrams were created in Visual Paradigm 15.1.
2
2.1.
Conceptual ERD
Figure 1: Conceptual ERD
3
2.2.
Logical ERD
Figure 2: Logical ERD
2.3.
Physical ERD
Figure 3: Physical ERD
4
3. SQL Implementation
The database was implemented in Oracle Application Express, which uses Oracle Database
12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production as a DBMS.
3.1.
DDL : Defining the database objects
CREATE TABLE Address (ID number(10) , CIty varchar2(50) NOT NULL, Street
varchar2(100) NOT NULL, ZIP number(6), PRIMARY KEY (ID));
CREATE TABLE Location (ID number(10), Name varchar2(100) NOT NULL, GPS
varchar2(255), AddressID number(10) NOT NULL, PRIMARY KEY (ID));
CREATE TABLE Mineral (ID number(10), Name varchar2(50) NOT NULL, Formula
varchar2(255), PRIMARY KEY (ID));
CREATE TABLE Person (ID number(10), Name varchar2(50) NOT NULL, Surname
varchar2(60) NOT NULL, Note varchar2(255), AddressID number(10), PRIMARY KEY
(ID));
CREATE TABLE Photo (ID number(19), DateTaken date NOT NULL, URL varchar2(255)
NOT NULL, Name varchar2(100) NOT NULL, Description varchar2(255), PersonID
number(10) NOT NULL, SampleID number(10) NOT NULL, PRIMARY KEY (ID));
CREATE TABLE Sample (ID number(10), Current_price number(10, 2), DateFound
number(10), Description varchar2(255), LocationID number(10) NOT NULL, FounderID
number(10), PRIMARY KEY (ID));
CREATE TABLE Sample_Mineral (SampleID number(10) NOT NULL, MineralID
number(10) NOT NULL, PRIMARY KEY (SampleID, MineralID));
CREATE TABLE "Transaction" (ID number(10), Type number(1) NOT NULL, Place
varchar2(255), Price number(10, 2), TransactionDate date, PersonID number(10) NOT
NULL, SampleID number(10) NOT NULL, PRIMARY KEY (ID));
5
Constraints:
ALTER TABLE Person ADD CONSTRAINT FKPerson626786 FOREIGN KEY
(AddressID) REFERENCES Address (ID);
ALTER TABLE "Transaction" ADD CONSTRAINT FKTransactio893823 FOREIGN KEY
(PersonID) REFERENCES Person (ID);
ALTER TABLE Sample_Mineral ADD CONSTRAINT FKSample_Min990416 FOREIGN
KEY (MineralID) REFERENCES Mineral (ID);
ALTER TABLE Sample ADD CONSTRAINT "comes from" FOREIGN KEY (LocationID)
REFERENCES Location (ID);
ALTER TABLE Sample_Mineral ADD CONSTRAINT "consist of" FOREIGN KEY
(SampleID) REFERENCES Sample (ID);
ALTER TABLE Sample ADD CONSTRAINT "found by" FOREIGN KEY (FounderID)
REFERENCES Person (ID);
ALTER TABLE Location ADD CONSTRAINT "is at" FOREIGN KEY (AddressID)
REFERENCES Address (ID);
ALTER TABLE Photo ADD CONSTRAINT "is captured on" FOREIGN KEY (SampleID)
REFERENCES Sample (ID);
ALTER TABLE "Transaction" ADD CONSTRAINT "part of" FOREIGN KEY (SampleID)
REFERENCES Sample (ID);
ALTER TABLE Photo ADD CONSTRAINT "took by" FOREIGN KEY (PersonID)
REFERENCES Person (ID);
6
3.2.
DML: Inserting the data (examples)
INSERT INTO Address(ID, City, Street, ZIP) VALUES (1,'Prague', 'Kamycka', '16500');
INSERT INTO Address(ID, City, Street, ZIP) VALUES (2,'Pribram', 'Brezove Hory',
'16500');
INSERT INTO Location(ID, Name, GPS, AddressID) VALUES (1, 'Pribram - ', '',2);
INSERT INTO Mineral(ID, Name, Formula) VALUES (1, 'Silver', 'Ag');
INSERT INTO Mineral(ID, Name, Formula) VALUES (2, 'Calcite', 'CaCO3');
INSERT INTO Person(ID, Name, Surname, Note, AddressID) VALUES (1, 'Petr', 'Hanzlik',
'', '1');
INSERT INTO Photo(ID, DateTaken, URL, Name, Description, PersonID, SampleID)
VALUES (1, 10/10/1983, ' 'eosj93324.jpg',
'macro-photo', 1, 1);
INSERT INTO Sample(ID, Current_price, DateFound, Description, LocationID, FounderID)
VALUES (3, 300, 4/4/1983, 'rare specimen with aesthetic silver wires on calcite with
stephanite ', 1, 1);
INSERT INTO Sample_Mineral(SampleID, MineralID) VALUES (1, 2);
INSERT INTO Sample_Mineral(SampleID, MineralID) VALUES (1, 2);
INSERT INTO "Transaction"(ID, Type, Place, Price, TransactionDate, PersonID, SampleID)
VALUES (1, 1, 'Prague', 3500, '12/12/2017', '1', 1);
7
3.3.
•
SQL Queries
Find all the samples from locality
SELECT * FROM sample where LocationID = (SELECT ID FROM Location
WHERE name LIKE ‘Pribram%’);
•
Find all the localities in collection where a mineral was found
SELECT * FROM Location WHERE ID IN (SELECT LocationID FROM
sample_mineral sm INNER JOIN sample s ON s.id = sm.sampleID INNER JOIN
mineral m ON sm.MineralID = m.id WHERE m.Name = ‘Silver’);
•
Find all photos of a mineral
SELECT * FROM photo WHERE sampleID IN (SELECT sm.sampleID FROM
sample_mineral sm INNER JOIN mineral m ON sm.MineralID = m.id WHERE
m.Name = ‘Silver’);
•
Get all minerals found by certain person
SELECT DISTINCT m.* FROM sample_mineral sm INNER JOIN sample s ON s.id
= sm.sampleID INNER JOIN mineral m ON sm.MineralID = m.id WHERE
s.founderID = (SELECT id FROM person WHERE Name = ‘Petr’ AND Surname =
‘Hanzlik’);
•
Get all samples purchase from certain person
SELECT s.* FROM Transaction t, Person p, Sample s WHERE t.personId = p.id
AND t.sampleId=s.id AND p.name=’Petr’ AND p.surname = ‘Hanzlik’
8
4. Conclusion
This project contains a basic proposal for a database, which can be used in a collection
management system. It contains definitions of essential database objects, and examples of
possible use cases realised in the form of SQL queries. This project is an essential part of a
possible implementation of full scale systems.
9