Os DDD
Os DDD
Os DDD
Unit 5.2
Database design and development
OSAMA ARSHAD | 19/04/2021
Module leader: Miss Loraine Annie
localhos
2
Contents
Task 1......................................................................................................................................4
Identifying Entities and their attributes..............................................................................................4
Mapping/ Cardinality.........................................................................................................................6
Entity relationship Diagram for the scenario......................................................................................7
1.b) Normalise the data to 3rd normal form........................................................................................7
Normalisation.....................................................................................................................................7
1.c) Produce design documentation in response to the client brief ensuring this shows the design of
the tables, constraints, SQL queries, forms and security measures..................................................12
This provides evidence for LO2- [2.2]................................................................................................12
Data Dictionary.................................................................................................................................12
Data Dictionary Tables:....................................................................................................................13
Constraints.......................................................................................................................................15
Entity Integrity Constraints...............................................................................................................15
INDEX...............................................................................................................................................16
TRIGGER...........................................................................................................................................16
FORMS..............................................................................................................................................17
SECURITY MEASURES (DAC,MAC,RBAC)............................................................................................18
i. RBAC (Role Based Access Control)..............................................................................................................18
ii. DAC (Discretionary Access Control)............................................................................................................19
MAC (Mandatory Access Control)........................................................................................................................20
Task 2....................................................................................................................................22
2.a) Implement the database using the designs you have created in Task 1. Ensure that your
database includes all the features you designed in activity one.......................................................22
Screen shots of all tables..................................................................................................................22
Screen shots of all constraints. Foreign Key(similarly screenshots of all constraints)........................28
Implement a suitable graphical user interface..................................................................................30
Task 3....................................................................................................................................31
Trigger test.......................................................................................................................................31
Revoke test:......................................................................................................................................32
Grant test.........................................................................................................................................33
Edit privileges: User account 'root'@'localhost'....................................................................33
Primary key test:..............................................................................................................................34
localhos
3
localhos
4
Figure 24 ODBC..........................................................................................................................................50
Task 1
Using the information you have been provided with and some additional external research,
1.a) Plan and produce a design for a complex relational database based on a response to the
client brief.
There are 6 Entities in the database the data is stored unnormarlised, below are the
detail of entities and attributes with their constraint keys.
Entity 1 (Books)
It has 10 fields with Book_ID being the primary key.
Entity 2 (customer)
It has 9 fields with cust_id being the primary key
localhos
5
Attribute 5 email
Attribute 6 zip code
Attribute 7 City
Attribute 8 DOB
Attribute 9 Book id
Entity 3 (order)
It has 6 fields with order ID being the primary key
Attribute 1 ordere_id
Attribute 2 Order date
Attribute 3 ordere items qty
Attribute 4 price
Attribute 5 cust_id
Attribute 6 Book id
Entity 4 (staff)
It has 5 fields with staff ID being the primary key
Attribute 1 staff_id
Attribute 2 Staff name
Attribute 3 Email
Attribute 4 Phone
Attribute 5 salary
Entity 5 (supplier)
It has 4 fields with supplier ID being the primary key
Attribute 1 supplier_id
Attribute 2 name
Attribute 3 Email
Attribute 4 Company
address
Entity 6 (payment)
localhos
6
Each table has a constraint key (primary / foreign) that links them together.
Because the supplier company distributes the books to the pioneer book library, the books t
able is linked to the supplier table.
The books table, on the other hand, contains orders placed by customers and is maintained
by staff.
The staff checks the order and places it for the customer,
Mapping/ Cardinality
Mapping cardinalities is most useful when describing binary relationship sets. Although
they can contribute to the complexity of relationship sets, they are not very useful in
describing complex relationships.
There are four different mapping cardinalities for a binary relationship set R on an entity
set A and B. The following are some of them:
1. One to one (1….1)
2. One to many (1….M)
3. Many to one (M….1)
4. Many to many (M….M)
localhos
7
This is the (UNF data)Entity relationship model for the database Pioneer books library. As you
can see there is 6 tables with un-normlaised form data. Which can be difficult for the admin/staff
to modify, delete , update and inserting data and retrieve data.
Steps:
The pioneer book library receives books from a supplier.
Order is placed by the customer.
Customer makes a payment
The staff member is in responsible of the orders.
The books table and the supplier table were managed by the staff.
localhos
8
Normalisation
1. Book table
UNF 1NF 2NF 3NF
Book id (fk)
Supplier id (fk)
Staff id (fk)
2. Customer table
UNF 1NF 2NF 3NF
localhos
9
dob
Here above 2 customer table, we removed the BOOK ID attribute the repeating data so that we
can have customer table information stored separately. In addition customer id is primary that
can be linked with other tables to retrieve the data.
3. Staff table
4. supplier table
localhos
10
5. order table
Cust add
Cust email
3NF data as you can see we create 2 tables from UNF order data. Staff placed order for
customer with his/her customer ID that is foreign key in order table( related to customer table
where it is primary key), so that staff person can stored the information and placed orders.
6. payment table
6 PAYMENT TYPE
6 c_id PAYMENT TYPE no. PAYMENT TYPE no. PAYMENT TYPE no.
(pk) (pk) (pk)
6 order item qty Payment type name Payment type name Payment type name
6 order id C_id(fk) C_id(fk)
6 book id Order id(fk) Order id(fk) Payment type no. (fk)
localhos
11
Order id
Book id
All main keys have been designated as (PK) in the Normalisation, while foreign keys have been
marked as (FK) (FK).
Now, the data in the assignment and table is not normalized or prepared properly. The data
integrity and functional relationships are not maintained, and the data is not fully normalized.
In order to create the link, normalisation was performed on all tables. To build, several tables
must be separated and primary and foreign keys must be used. The following steps were done
to complete the Normalization:
So, based on this Figure 1, it’s the (customer table). It’s the 1NF Explanation in this table there
are duplicate data, so I separate them into different table. The figure 2, it’s the 3NF of the table
of customer. You will see that highlighted color I remove all duplicate data (b_id) and create
different table so as I can create the ER diagram.
localhos
12
dob
1.c) Produce design documentation in response to the client brief ensuring this
shows the design of the tables, constraints, SQL queries, forms and security
measures.
As you can see the ER diagram that is completely normalised upto 3NF, are linked to each other table by
colored relationship. Here are the 10 entities after normalisation upto 3NF, as you can see books table is
linked with(book_con) table in which Foreign keys are inserted to make a link with other tables to
retrieve a data.
Customer_add_detail has zip code as a being primary key, which has relation with the customer
detail table where the customer iD is being primary and zip_code attribute is foreign key.
Staff has staff id bein primary key and relation with cook_con tabke and other order table.
localhos
13
Supplier has supplier id which in primary key in there, which represent the book supplier by
which supplier has supplied the book. It has relation through book_con table.
Order table had divided into 2 tables to manage the customer order. In the order detail table,
order id, order date,, customer id, book id (which book order is placed), ordere QTY ( quantity of
book order), and payment type ( cash/ credit)
Payment type table which has 2 attribute with payment type code is being primary key to
difference between payment types.
(1- credit)
(2-cash)
Order checkout table is created to show the report of the order, where you can see order placed
report.
Green color is used to show the relation from one table to other tables.
Data Dictionary
A data dictionary is a set of names, terms, and attributes for various data elements and models.
They are used in databases and other information systems. The metadata more about
database is the data in a data dictionary. These components are then included into a database,
research project, or information system. Although there is variance, these are the most typical
items found in a data dictionary:
Attribute_name
Attribute_type
Entity-relationship(ER)
References data
localhos
14
localhos
15
Constraints
Constraints in a database are used to define rules for the data in a table. Constraints are
used to restrict the types of data that can be entered into a table. This ensures that the data
in the table is accurate and reliable. The action is cancelled if there is a conflict between the
constraint and the data action.
localhos
16
INDEX
In the referenced table, you must have specified a primary key (or at least an indexed
column) that will act as the foreign key in the referencing table. We have defined ‘zip
code' as a foreign key in the ‘customer' table in our example. A screenshot of the table
where you can add foreign keys is shown below.
As you can see the constraint action have 3 column in which you have to select the
attribute with real location table, it will automatically entered the primary key to the last
table.
TRIGGER
A trigger is a statement that is created automatically by the system in the first place of a
database alteration. If specific circumstances occur, specify an action to be taken.
Event: modification the database automatically activates trigger (an insertion, deletion,
update)
Condition: when the trigger activates a test or query checked for confirmation. (eg: for a
query: null is false, not null is true)
SYNTAX:
CREATE TRIGGER save_price AFTER INSERT ON details REFERENCING NEW
TABLE AS inserted FOR EACH STATEMENT WHEN TRUE BEGIN INSERT INTO
prices(order_id,b_id,price) SELECT I.order_id, I.b_id, P.price FROM inserted I JOIN
products P ON I.b_id = P.b_id END ;
localhos
17
create a Staff table where we have attribute, Staff name, staff id, staff email, staff phone
number, staff salary.
Go to the trigger>> add insert trigger>> Syntax
INSERT INTO STAFF VALUES( NULL, NEW.SALARY, ‘INSERTED’);
PRESS GO.
The new table will be create when you add salary it will revoke trigger send a error
message if the value is incorrect.
Output:
FORMS
Db Connection
localhos
18
localhos
19
GRANT privilage:
The GRANT command can grant a wide range of permissions, including
the power to CREATE tables and databases, READ and WRITE FILES,
and even SHUTDOWN the server.
RBAC is based on the functions they play in a system, rather than a user identity. These
rules are determined by an individual's job profile, responsibilities, and authority inside
an enterprise.
Users are granted distinct roles based on their duties, either statically or dynamically.
In some situations, the user executing a specific task or duty dynamically adjusts; as a
result, the job assignment should be adaptable.
localhos
20
RBAC 4 models:
In DAC (Discretionary Access Control), the data user determines the users' access
control policy.
The administrator has complete control over who has access to “read, write, execute,
search, create, and delete.”
DAC is known as a "need-to-know" access model as it needs permits to be provided to
those who require access.
.
localhos
21
• Although DAC is simple to use and understand, it does have several drawbacks, including:
localhos
22
1. 1. As shown in Figure 6, the first confidentiality and category levels are related to data
and user.
2. 2. The user should then be authenticated.
3. 3. When an user requests data and tries to access it, the operating system examines the
user's data and connects it to the security levels that is given to data in the permitted
database.
4. If the user's and data's confidentiality and category levels match, access is granted; if they
don't, access is denied.
localhos
23
Task 2
2.a) Implement the database using the designs you have created in Task 1.
Ensure that your database includes all the features you designed in activity
one.
localhos
24
localhos
25
localhos
26
localhos
27
localhos
28
localhos
29
localhos
30
Error occur when you try to enter the same duplicate key.
localhos
31
localhos
32
Task 3
3.a) Test the database and produce screen shot evidence to show the tests that
have been carried out and explain any errors that need to be resolved. Amend the
database based on the testing.
Trigger test
Test ID : T001
Test : INSERT INTO `book` (`book_id`, `book name `, `book author`, `year`, `publish date
Input `, `Description genre’, `page count`, `price `)
Pass / : PASS
Fail
Screensh :
ot
localhos
33
Revoke test:
Test ID : T002
Test Input :
Expected : Error Message “ #1829 - Cannot drop column 'staff_id': needed in a foreign key
Result constraint 'order_ibfk_1' of table 'osamadb books.order'
Actual : Error Message “ #1829 - Cannot drop column 'staff_id': needed in a foreign key
constraint 'order_ibfk_1' of table ‘osamadb books.order'
Result
Screenshot :
localhos
34
Grant test
Test ID : T003
Test :
Input
Actual :
Result Edit privileges: User account 'root'@'localhost'
Pass / : PASS
Fail
localhos
35
Screensh :
ot
Test : INSERT INTO `book`(`book_id`, `book name`, `author name`, `year`, `publish
Input date`, `description genre`, `page count`, `price`) VALUES ('1','Alice
grace','soon','2019','2019-12-1','history','44',0)
Pass / : PASS
Fail
Screensh :
ot
localhos
36
Test Input : INSERT INTO `supplier`(`supp_id`, `s_name` `S_email’, phone no) VALUES
(1,cath,'Xyz',[email protected]', 355678)
Screensho :
t
localhos
37
Test :
Input
Expected : Cannot delete or update a parent row: a foreign key constraint fails
Result (`osamadb`.`book_con`, CONSTRAINT `book_con_ibfk_3` FOREIGN KEY
(`O_staff_id `) REFERENCES `staff` (`OS_staff_id`)) ON DELETE CASCADE ON
UPDATE CASCADE)
Actual : Cannot delete or update a parent row: a foreign key constraint fails
(`osamadb`.`book_con`, CONSTRAINT `book_con_ibfk_3` FOREIGN KEY
Result
(`O_staff_id `) REFERENCES `staff` (`OS_staff_id`)) ON DELETE CASCADE ON
UPDATE CASCADE)
Pass / : PASS
Fail
Screensh :
ot
localhos
38
Login page
Test ID : T007
Screensho :
t
localhos
39
Steps :
Screenshot :
localhos
40
Order report
Test ID : T009
Steps :
Screenshot :
Test ID : T010
Steps :
Screenshot :
localhos
41
Task 4
4.a) Critically evaluates the design process and documentation that was produced
for Pioneer Books database identifying improvements with the design
documentation where appropriate.
Include the comments provided by Tutor on your first submission about the ER Diagram and
normalization. (Example: The ER diagram went through multiple changes according to the tutor’s
localhos
42
feedback as new relationships were added and some old were changed to remove errors from the
diagram, cardinality included etc….)
4.b) Reviews the database implementation process and explain what was
successful and what you would do differently if you were to do this again.
I begin by creating the database and filling it with tables. Then I began adding attributes and
entering certain tables with data, and the most important thing was to input the correct table
because some will be related to others. For example, I fill data in the book table and book ID is
used as a primary key so I can fill the book connection table. Why do I do this first because later
I will got problem while filling the data in the other table. There are some tables which have
relationship with the main table. Just look down the screenshot to have an overview what I’m
saying.
localhos
43
localhos
44
So in the above figures you can see the staff table and supplier table had to created first so that
they can link to the book connection table. Where as in the book connection BOOK ID and
STAFF ID, SUPPLIER ID are foreign key which links to the BOOK detail Table.
localhos
45
They may create an Android or iOS app or a website so that their consumers can access their
personal information or information about the pioneer book library at any time. All database
permissions must be granted to the application.
Introduction
localhos
46
OLTP:
OLTP is a process that focuses on the integrity, performance, and availability of data. It is mainly
concerned with query processing and multi-access scenarios.
OLAP:
OLAP stands for Online Analytical Processing, and it is a type of software that allows users to evaluate
data from various databases at the same time. It's a tool that allows analysts to obtain and analyze
business data from various perspectives. Data can be pre-calculated and pre-aggregated using OLAP,
which speeds up analysis.
1 or even more cubes are used to split OLAP databases. These cubes are constructed in such a way that
it is simple to create and read reports. Online Analytical Processing (OLAP) is a term that refers to the
process of analyzing data online.
A data warehouse extracts data from a variety of sources and formats, including text files, excel sheets,
multimedia files, and so on.
The data is extracted and modified after it has been obtained. Data is fed into an OLAP server (or OLAP
cube), which calculates information ahead of time for future analysis.
DATA WAREHOUSE
Data warehousing (DW) is a method of gathering and analyzing data from many sources in order to get
useful business insights. Typically, a data warehouse is used to integrate and analyze corporate data
from many sources. The data warehouse is the heart of the business intelligence (BI) system, which is
designed to analyze and report on data.
A Data Warehouse is a central repository where data through one or more data sources is stored. The
transaction system and certain other relational databases feed data from the data warehouse.
1. Organized
2. Structured semi-structure
3. Data that is unstructured
localhos
47
4.d) Explains how Pioneer Books can connect the database to other applications
that it may use within the business.
Firstly we have to create a database without any data redundancy, which can be done by doing the data
normalization. Sorting data from table to table 1NF, 2NF, 3NF, so that I can remove the duplicate data
from the table steps by step. From task 1 to task 2, the database is created using the Normalisation
method first, then the database is created and the ERD diagram is obtained. The SQL construct table
task 1(a) demonstrates how I implemented the pioneer books library in the databases. Doing some
study on a database's population and explaining it in the context of the assignment. The next job is to
provide the query as well as the result in two different images. The first goal is to write a basic query to
display the data in each table, which is followed by task 1(a). The ODBC and JDBC drivers in MS- SQL
based Application Programming Interface(API) enables software and programs to connect to databases
through SQL. OBDC allows the window software programs and JDBC allows Java programs to access and
connected to data. By allowing these programs which can connect the database of Pioneer books to
other application, these API’s on a client system to communicate with a data source on the same client
machine or on a different server computer.
localhos
48
For example:
Class.forName("oracle.jdbc.odbc.JdbcOdbcDriver");
2. Make connection
The getConnection() function of the DriverManager class is used to create a connection object.
A database url, user name, and password must be provided.
Example : Creating connection with oracle driver
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1534:XE","username","password");
3. Create SQL Statement
The Connection interface gives the createStatement() method to create SQL statement.
Syntax:
public Statement createStatement( ) throws SQLException
4. Execute SQL Queries
The Statement interface provides the executeQuery( ) method to execute SQL statements.
Syntax:
public ResultSet executeQuery(String sql) throw SQLException
5. Closing the Connection
The Connection interface provides close( ) method, used to close the connection. It is invoked
to release the session after execution of SQL statement.
Syntax:
public void close( ) throws SQLException
Example:
con.close( );
localhos
49
Figure 24 ODBC
4.e) Recommends to Pioneer Books a database management system they can use
to maintain the database you have created.
Data model
As you can see in my ERD graphic, data modelling is the process of establishing a data model for data to
be stored in a database.
localhos
50
There are 11 tables in the databse which have connection related to each other. For example:
The number of table customer id utilized has a relationship with the number of order detail, which has a
relationship with the order checkout. Now I'll show you how to create a table in the database. First, I'll
input data, then I'll create a foreign key relationship.
localhos
51
As you can see the customer id is shown in the figure. Unique key of customer id is foreign key in the
order detail table.
Now you can see the, here customer id is linked to two table 1-order detail and 2- order checkout.
Hierarchical
A data model where the data is structured into a tree-like structure is known as a hierarchical database
model. The information is kept in the form of records that are linked together. To obtain data from the a
hierarchical database, you must first traverse the entire tree, beginning at the root node.
The hierarchical model optimizes the performance of queries. Since data is stored in the form of records,
you don't have to contact the database server for every request. You can by-pass the database server,
going right to data that is closer to you on the tree.
localhos
52
Book table
As it has a less drawbacks than hierarchy where you have to adjust each table with their attribute and
column and display relation.
localhos
53
Rational database is most efficient and flexible model. It is advance model database that is use in today
as compare to hierarchy model which is now old.
Data accuracy: Different tables in the pioneer books library can be identified with each other in a
relational database model by utilizing the essential key and unfamiliar key standards. Thus, the
information is non-repetitive. There is no chance of information duplication in the pioneer book
database. Subsequently, data in a relational database is more accurate than data in any other database
system.
Easy to access data: There is no pattern or path for accessing the data, unlike other databases that can
only be accessed by traveling through a tree or hierarchical model. Any table in the relational database
can be queried by anyone who has access to the data.
Normalisation: normalisation is done when the data is unnormalised which make trouble to store ,
update, delete and retrieve data from the table. Pioneer books data is normalised 1NF to 3NF to avoid
all the error that may occur during storing data.
localhos
54
References
Advantages, R., 2021. Relational Database Advantages | 8 Advantages of Relational Database. [online]
EDUCBA. Available at: <https://www.educba.com/relational-database-advantages/> [Accessed 24
May 2021].
Shelar, N., 2021. Access Control Policies (MAC, DAC, RBAC, ABAC) | The Polymath Blog. [online] The
Polymath Blog. Available at: <https://neelshelar.com/access-control-policies-mac-dac-rbac-abac/>
[Accessed 24 May 2021].
Guru99.com. 2021. What is Data Warehouse? Types, Definition & Example. [online] Available at:
<https://www.guru99.com/data-warehousing.html#3> [Accessed 24 May 2021].
Guru99.com. 2021. What is OLAP? Cube, Operations & Types in Data Warehouse. [online] Available at:
<https://www.guru99.com/online-analytical-processing.html> [Accessed 24 May 2021].
localhos