You are on page 1of 20

Database Case Study

Report
MIS602 Data Modelling and Database Design
1

Index
1. ER Diagram....................................................................................................................................2
2. Relational Model............................................................................................................................3
a. Business rules and assumptions................................................................................................3
3.Creating Tables and populating data...................................................................................................4
3.1. Contract......................................................................................................................................4
3.2. Software......................................................................................................................................4
3.3. Vendor........................................................................................................................................5
3.4 License.........................................................................................................................................6
3.5 Manager......................................................................................................................................7
3.6 Staf.............................................................................................................................................7
3.7 Devices.........................................................................................................................................8
4. Business Insights..............................................................................................................................10
4.1 SQL Query with condition..........................................................................................................10
4.2 Group by query..........................................................................................................................10
4.3 Join query..................................................................................................................................11
4.3 Nested Query.............................................................................................................................12
4.4 Cost issues.................................................................................................................................13
5. Data Visualization............................................................................................................................17
2

1. ER Diagram
3

2. Relational Model

a. Business rules and assumptions

 Contracts last for a fixed 1 term of one year.


 All software is licensed by installation per device.
 A contract may have many licenses and many software, but
 Each license have an expiry date and corresponds to one software only.
 Each license is valid for one device only.
 A contract can have only one vendor, but many software from the same vendor.
 Every device is assigned to one staf member, which is or have one manager.
 Every manager responsible for the staf member is responsible for the license of the software
installed in this same staf member.
 The same software can exist under diferent contracts,
4

 All subscription are paid by month. No consumption licenses.

3.Creating Tables and populating data


3.1. Contract

CREATE TABLE Contract (


Contract_ID INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY
);

insert into contract values (01);


insert into contract values (02);
insert into contract values (03);
insert into contract values (04);

ALTER Table contract add column `Expiry date` date;

insert into contract (contract_id,`expiry date`) values (05,"2022-04-26");


UPDATE contract
SET
`expiry date` = '2021-11-26'
WHERE
contract_id = 4;
UPDATE contract
SET
`expiry date` = '2022-03-25'
WHERE
contract_id = 3;
UPDATE contract
SET
`expiry date` = '2022-06-25'
WHERE
contract_id = 2;
UPDATE contract
SET
`expiry date` = '2021-12-28'
WHERE
contract_id = 1;

3.2. Software

CREATE TABLE Software (


SKU INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Software_name VARCHAR(30) NOT NULL
);
alter table software add column vendor_name varchar(30), add column contract_number
varchar(30);

ALTER TABLE software RENAME COLUMN vendor_name TO vendor_id;

insert into software (SKU, Software_name,Vendor_name) values (01,"Snagit", "01");


insert into software values (02,"Photoshop", "02");
insert into software values (03,"Autocad", "03");
insert into software values (04,"Database11g", "04");
insert into software values (05,"Database12c", "04");
insert into software values (06,"Windows8", "05");
insert into software values (07,"Windows10", "05");
insert into software values (08,"Office2016", "05");
5

insert into software values (09,"Lightroom", "02");


insert into software values (10,"Antivirus", "06");
insert into software values (11,"Financials", "07");
insert into software values (12,"Beyond Compare", "08");
insert into software values (13,"Linux 5.0", "09");
insert into software values (14,"BRIEF", "10");

3.3. Vendor

/***** CREATING AND FILLING VENDOR TABLE ****/

CREATE TABLE vendor (


vendor_name VARCHAR(30) NOT NULL
);
alter table vendor add column vendor_id varchar (3);

insert into vendor (vendor_name, vendor_id) values ("Techsmith",01);


insert into vendor (vendor_name, vendor_id) values ("Adobe",02);
insert into vendor (vendor_name, vendor_id) values ("Autodesk",03), ("Oracle",04),
("Microsoft",05),
("Kasperski",06),("SAP",07),("Scooter Software",08),("Rehat",09),("Underware",10);
6

3.4 License
CREATE TABLE license (
license_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
SKU VARCHAR(3),
contract_id VARCHAR(3),
asset_id VARCHAR(3)
);SELECT
*
FROM
license;

/* contract 1, techsmith, snaig, device 1 and 2 */


insert into license (license_id, SKU,contract_id,asset_id) values (01,01,"01",01);
insert into license (license_id, SKU,contract_id,asset_id) values (02,01,"01",02);

/* contract 2, adobe, photshop, device 1 and 2 */


insert into license (license_id, SKU,contract_id,asset_id) values (03,02,02,02);
UPDATE license
SET
asset_id = 01
WHERE
license_id = 03;
insert into license (license_id, SKU,contract_id,asset_id) values (04,02,02,02);

/* contract 3, adobe, lightroom, device 1 and 2 */

insert into license (license_id, SKU,contract_id,asset_id) values (05,02,09,01);


insert into license (license_id, SKU,contract_id,asset_id) values (06,02,09,02);

/* contract 3, microsoft, windows 8 device 1,2,3,4 + windows 10 device 5,6 */

insert into license (license_id, SKU,contract_id,asset_id) values (07,03,06,01);


insert into license (license_id, SKU,contract_id,asset_id) values (08,03,06,02);
insert into license (license_id, SKU,contract_id,asset_id) values (09,03,06,03);
insert into license (license_id, SKU,contract_id,asset_id) values (10,03,06,04);
insert into license (license_id, SKU,contract_id,asset_id) values (11,03,07,05);
insert into license (license_id, SKU,contract_id,asset_id) values (12,03,07,06);
7

3.5 Manager

create table manager (manager_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,


name varchar(30));
insert into manager values (01,"Allan Amorim"),
(02,"Will Camara");

3.6 Staf
CREATE TABLE staf (
staf_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30),
role VARCHAR(15),
manager_id VARCHAR(3)
);

insert into staf values (01,"Allan Amorim",01),


(02,"Will Camara",02),
(03,"Lisa Malady",01),(04,"Matt Sauerbrown",01),
(05,"Brian Adams",02),(06,"Gabriel Kalliman",02);
8

3.7 Devices

CREATE TABLE device (


asset_id INT NOT NULL,
device_type VARCHAR(30) NOT NULL,
device_name VARCHAR(30) NOT NULL,
staf_id VARCHAR(30),
PRIMARY KEY (asset_id));

/* 2. INCLUDING INITAL DEVICE DATA */

insert into device (asset_id, device_type, staf_id)


values (01,"notebook",01), (02,"desktop",01), (03,"notebook",02),(04,"destktop",02),
(05,"tablet",02),(06,"notebook",03);

/* a new column was created later for device name */

insert into device (asset_id, device_type, staf_id, device_name)


values (07,"netbook",07, "Apple netbook"), (08,"desktop",07,"Lenovo All-in-One");
9

/* couting types of device */

select device_type, count(device_type) as quantity from device group by device_type;


10

4. Business Insights
4.1 SQL Query with condition
/*
DEVICES PER EMPLOYEE
VIEW:
*/

CREATE VIEW Device_per_Employee AS


SELECT
staf.name AS Name,
device.device_name AS Device,
software.Software_name AS 'Software installed'
FROM
staf,
license,
device,
software
WHERE
staf.staf_id = device.staf_id
AND device.asset_id = license.asset_id
AND license.SKU = software.sku;

4.2 Group by query


/*** COUNTING HOW MANY DEVICES PER EMPLOYEE USING GROUP BY ***/

SELECT `Software installed`, count(`Software installed`) as Quantity from


Device_per_employee
group by `Software installed`;
11

4.3 Join query


SELECT
device.device_name,
license.license_id,
contract.`Expiry date`
FROM
device
INNER JOIN
license ON device.asset_id = license.asset_id
INNER JOIN
contract ON license.contract_id = contract.contract_id
ORDER BY `Expiry date` ASC;

Create view licenses_installed as


SELECT
device.device_name,
license.license_id,
contract.`Expiry date`
FROM
device
12

INNER JOIN
license ON device.asset_id = license.asset_id
INNER JOIN
contract ON license.contract_id = contract.contract_id
ORDER BY `Expiry date` ASC;
select * from licenses_installed;

select
licenses_installed.device_name,
licenses_installed.license_id,
licenses_installed.`Expiry date`,
licensed_software.software_name from licenses_installed inner join licensed_software
on licensed_software.license_id = licenses_installed.license_id;

/*
NOW INCLUDING VIEW FOR SOFTWARE NAME - LICENSE
IT WILL BE USED IN THE INEER JOIN TO SHOW SOFTWARE, EXPIRY, LICENSE, DEVICE*/

CREATE VIEW licensed_software as select license.license_id, software.software_name


from license, software where license.sku = software.sku; select * from licensed_software;

The creation of views or inner join queries allow the visualization of licenses on each
device in order to be informed about the expiration date. If it is recommended to update
Windows 8 for Windows 10, it is possible to query only Windows 8 devices and order by
its expiration date, in order to prepare a schedule for the upgrading.

This same query can be organized in many ways, like device type, if we want to make the
assumption that notebooks will require Windows 8 and desktops will have Windows 10,
for a future update.

4.3 Nested Query


SELECT
software_name, device_name, `Expiry date`
FROM
installed
WHERE
`Expiry date` IN (SELECT
`Expiry date`
FROM
installed
13

WHERE
YEAR(`Expiry date`) < 2022)
ORDER BY `Expiry date` ASC;

This query will answer which licenses are about to expire, for each software and device.

4.4 Cost issues


CREATE VIEW device_per_staf AS
SELECT
device.device_type, staf.name
FROM
device
INNER JOIN
staf ON device.staf_id = staf.staf_id;SELECT
*
FROM
device_per_staf;

SELECT
device_type, COUNT(device_type) AS Quantity, name
FROM
device_per_staf
WHERE
device_type = 'notebook'
GROUP BY name
UNION SELECT
device_type, COUNT(device_type), name
FROM
device_per_staf
WHERE
device_type = 'netbook'
GROUP BY name
UNION SELECT
device_type, COUNT(device_type), name
FROM
device_per_staf
WHERE
device_type = 'desktop'
GROUP BY name
UNION SELECT
device_type, COUNT(device_type), name
FROM
14

device_per_staf
WHERE
device_type = 'tablet'
GROUP BY name
ORDER BY Quantity DESC;

This query allows us to find out which staf has more than one device of the same type.
In this example Willian Martins has more than one netbook, what could be a mistake or
an issue to be solved, considered a bad allocation of assets. Not only the company can
save money ensuring each staf member has one device from any kind, but also check if
they have two licenses for the same software in these devices.

In this next query, for example, the view that shows devices per employee is used. The
view was updated in order to display the type of device as well. So this next query will
demonstrate how many similar software are installed for specific members of staf . We
know already that Willian has two netbooks. He also has a desktop. It is acceptable to
have a Windows 8 for a desktop and another Windows 8 for a notebook if the employee
needs to have two devices, but it would be a duplication issue if he has two versions of
the same software for the same device, as shown below:

SELECT
name,
`software installed`,
COUNT(`software installed`) AS Quantity,
device_type
FROM
device_per_employee
WHERE
(name = 'Willian Martins'
AND device_type = 'netbook')
GROUP BY `software installed`
UNION SELECT
name,
`software installed`,
COUNT(`software installed`) AS Quantity,
device_type
FROM
device_per_employee
WHERE
(name = 'Willian Martins'
AND device_type = 'desktop')
GROUP BY `software installed`
UNION SELECT
name,
`software installed`,
15

COUNT(`software installed`) AS Quantity,


device_type
FROM
device_per_employee
WHERE
(name = 'Allan Amorim'
AND device_type = 'notebook')
GROUP BY `software installed`
UNION SELECT
name,
`software installed`,
COUNT(`software installed`) AS Quantity,
device_type
FROM
device_per_employee
WHERE
(name = 'Allan Amorim'
AND device_type = 'desktop')
GROUP BY `software installed`;

Alternatively, how many devices per employee in general:

SELECT
name, COUNT(DISTINCT device) AS Quantity
FROM
software_per_Employee
WHERE
staf_id = 1
UNION SELECT
name, COUNT(device) AS Quantity
FROM
software_per_Employee
WHERE
staf_id = 2
UNION SELECT
name, COUNT(device) AS Quantity
FROM
software_per_Employee
WHERE
staf_id = 3
UNION SELECT
name, COUNT(device) AS Quantity
FROM
software_per_Employee
WHERE
staf_id = 7;
16

5. Data Visualization
17

The information of how many software per device may demonstrate duplicated licenses, if the case.
In our example it does not occur, since ach device has one software of a kind each. However it can
also demonstrate which device has more software installed than the others, thus the need for too
many programs in a unique device could be reviewed.

It is important to have visualizations that demonstrate the need for renewal or risk of getting an
unlicensed device. In this case contract number 5 is about to expire and should be checked. In the
other hand, some upgrades may be postponed or delayed by checking log contracts as well. For
instance, a Windows 8 replacement for Windows 10 may not be recommended if the license for this
Windows 8 is going to be valid for nearly one year and is already paid for.
18

How many software are installed

2 2 2 2 2

Snagit Photoshop Lightroom Windows8 Windows10 Office2016

How many devices per type


0
Lisa Malady 0 1
0
1
Will Camara 1
1
1
0
Allan Amorim 1
1
0
0
Willian Martins 0
0
2
0 0.5 1 1.5 2 2.5
netbook notebook desktop tablet

How many devices

1
0 0
1 1
2 0
1 1 1
0 0
Willian Martins Allan Amorim Will Camara Lisa Malady
netbook notebook desktop tablet
19

The demonstration of how many software and what kind of software may lead to the information of
a company bias, and tendency that could be reviewed plus a plan for upgrading. At the same time,
some visualizations on how many netbooks, tablets or notebooks each employee has is also useful. It
is expected to have one notebook and desktop for instance, but why Willian currently holds two
devices of the same type? Why a member of the staf holds two notebooks? Is there a reason, or is
this a case of improper asset allocation? This analysis is combine with the device count visualization,
since the case of Will Camara having 4 devices could be more justified than Willian Martins having
two devices, since Will may need one device of each kind for his role. It could be an assumption that
one of Willian’s device – which is a netbook - could be allocated to Lisa, who was one device only – of
a diferent kind - in the above demonstration.

You might also like