Академический Документы
Профессиональный Документы
Культура Документы
Introduction to Databases
(CT042-3-1)
WEIGHTAGE: 50%
___________________________________________________________________________
INSTRUCTIONS TO CANDIDATES:
2. Students are advised to underpin their answers with the use of references (Cited
using the Harvard Name System of referencing).
6. Where the assignment should be submitted in both hard copy and softcopy, the
softcopy of the written assignment and source code (where appropriate) should
be on a CD in an envelope/ CD cover and attached to the hardcopy.
We wish to express a sincere gratitude and warm appreciation to LBEF collage for assigning
us this task. We are delighted for having enhancement of our knowledge about Introduction
to Databases.
This project report is prepared for partial fulfillment of the requirement for the degree of
BSC.IT in accordance to the rules and regulation prescribed by Asian Pacific University
(APU). We are very grateful to our teacher Mr. Ramesh Suwal sir for his guidance and
support which help us in completing our assignment.
Lastly, we would like to thank our collage LBEF and our teacher Mr. Ramesh Suwal, who
helped us with proper guideline in preparation of our assignment.
Yours sincerely,
i
Table of Contents
Acknowledgment ..................................................................................................................................... i
Table of Contents .................................................................................................................................... ii
1. Introduction .................................................................................................................................... 1
1.1 Types of Database ................................................................................................................... 1
1.2 Components of Database........................................................................................................ 2
1.3 Background of Project............................................................................................................. 3
1.4 Project Aims and Objective ..................................................................................................... 3
1.5 Operation Environment .......................................................................................................... 4
2. ER Modelling ................................................................................................................................... 5
3. Business Rules ................................................................................................................................. 7
4. Normalization Process .................................................................................................................... 8
5. Database Schema .......................................................................................................................... 24
5.1 Logical Database ................................................................................................................... 24
5.2 Physical Database ................................................................................................................. 24
6. Data Dictionary ............................................................................................................................. 25
7. SQL Statements ............................................................................................................................. 29
7.1 Data Definition Language (DDL) ............................................................................................ 29
7.2 Data Manipulation Language (DML) ..................................................................................... 29
8. Workload Matrix ........................................................................................................................... 31
ii
1. Introduction
A database is a collection of information, which is organized in such a way, so it can be easily
accessed, managed and updated digitally. Data is organized into rows, columns and tables and it is
indexed to make it easier to find relevant information. Data is updated, expanded and deleted as new
information added with help of SQL query.
Relational Database
This is the most common of all the different types of databases. In this, the data in a relational
database is stored in various data tables. Each table has a key field, which is used to connect it to other
tables. Hence, all the tables are related to each other through several key fields. These databases are
extensively used in various industries and will be the one you are most likely to come across when
working in IT. Example: Microsoft SQL Server, Oracle and Sybase.
Operational Database
In everyday operation, an organization generates a huge chunk of data oriented with services such as,
inventory management, purchases, transactions and financials is called operational database
management system. All this data is collected in a database, which is often known by several names
such as operational/production database, subject-area database or transaction databases. It is one of
the important database as it includes the customer database and inventory database.
Distributed Database
A distributed database is a database in which storage devices are not all attached to a common
processing unit such as the CPU (Central Processing Unit). It may be stored in multiple computers
located in the same physical location, or may be dispersed over a network of interconnected
computers. (Expert, 2009)
1
1.2 Components of Database
Data
Data is distinct pieces of information, usually formatted in a special way. Data
Table
Tables are where the data are entered. Table consists of fields (columns) and records
(rows).
Queries
Queries are questions about the data in a database. A query consists of specifications
indicating which fields, records and summaries user want to see from a database. Query
allows a user to interact with the database.
User
User account must have been established for the user, with information about the user
being stored in data dictionary to connect with the database. Users who have been granted
the privilege to perform so can create users. While creating a database user account,
following attributes must be specified:
Username
Authentication method
User role
System privilege (Oracle, 2016)
Procedure
A procedure is a subroutine like a subprogram in a stored database. A procedure has a
name, a parameter list and SQL statements. Relational database system supports
procedure. Procedures are fast as SQL server takes some advantage of cache, just as
prepared statements do. Stored procedure are always available as source code in the
database itself. (W3Resource, 2014)
2
1.3 Background of Project
APU E-Bookstore is a design of database system, which refers to library systems, which
are generally small or medium in size. It is used by bookstore manager to manage the e-
library using a computerized system where he/she can tackle with various records like
issue of books, return of books, purchase of new books, addition of new member, book
receipts etc. With this computerized database system there will be no loss of book record
or member record, which generally happens when a non-computerized system is used.
In addition, the user can generate various report. User is able to generate different kinds
of reports like lists of members registered, list of books purchased, book issue and book
return reports. All these modules are able to help librarian to manage the library with
more convenience and in a more efficient way as compared to library systems, which are
not computerized.
3
1.5 Operation Environment
4
2. ER Modelling
5
Advantage of ER model
Disadvantage of ER model
6
3. Business Rules
7
4. Normalization Process
Normalization is systematic process of reducing complexity of an entity by
distributing the attribute to different entities. Data Normalization is a technique of
organizing the data in a database. Normalization is systematic approach of
decomposing tables to eliminate data redundancy and undesirable characteristics like
insertion, update and Deletion Anomalies. It is a multi-step process puts data from
the relation tables.
8
Advantages
Disadvantages
a. Requires much more CPU, memory, and I/O to process thus normalized data
gives reduced database performance.
b. Requires more joins to get the desired result. A poorly written query can bring
the database down.
c. Maintenance overhead. The higher the level of normalization, the greater the
number of tables in the database.
In most of the cases, data may still subject to third normal form. In this case,
database administrator has to perform further additional normalization form to
solve the anomalies, which are:
In the project we have done up to 3NF which we will show systematically process to 3NF.
First, there were three tables before any form of normalization was applied to the unmanaged
database. The structure of the tables was like:
9
Purchase_ Book_entry book_n book_cate order_ book_author publisher_name publisher_add book_pric
date _date ame gory invoic e
Purc
e_num
hase
_id
1 2017-03-26 2017-03-27 Java, Technical 555 Sunni Singh Baba Ji Bouddha, 552,553
MySQL Darlami Publication Tusal
2 2017-04-25 2017-04-21 Guitar Skill 556 Peter Kancha Baba Ji Bouddha, 590,600
lesson Publication Tushal
Is_d sales_ Member_n book_nam book_g sales_order_i book_auth publisher_ publisher_add book_p Memb
eliv date ame e enre nvoice_numb or name rice er_add
ered er ress
0 2017- Kajol Java, Technic 555 Sunni Tech Mcgraw Hill -2 340, Deural
04-25 MySQL al Singh Geek 230 i
Darlami
1 2017- Bhuwan Guitar Skill 556 Peter Baba Ji Bouddha, 590, Orali
04-25 Lesson Kancha Publicatio Tushal 600 Chow
n k
10
Before First Normal Form(1NF), our users table looked like:
11
Above we can see unmanaged table for purchase.
For applying First Normal Form to purchase table, we will remove repeated data in a cell
and identify primary keys.
Purchase_id invoice_ Book_entry book_n book_cate order_ book_author publisher_name publisher_add book_p
date _date ame gory invoic rice
e_num
1 2017-04-25 2017-04-22 Java Technical 123 Sunni Singh Tech Geek Bouddha, Tush 340
1 2017-04-25 2017-04-22 MySQL Technical 123 Sunni Singh Tech Geek Bouddha, Tush 230
2 2017-04-25 2017-04-21 Guitar Skill A23 Peter Kancha Baba Ji Bouddha, Tush 500
2 2017-04-25 2017-04-21 Lesson Skill A23 Peter Kancha Baba Ji Bouddha, Tush 600
In above figure, we have removed multiple values separated by commas in same table cell.
Then we first brought our Sales table in to 1NF like following where there were no multiple
values in a single table cell. After 1NF, our Sales table looked like:
12
is_d sales_ Mem book_ book_genr sale book_author publisher publisher_ad book Member_ad
eliv date ber_n name e s_or _name d _pric dress
ered ame der_ e
invo
ice_
num
ber
0 2017- Kajol Java Technical 555 Sunni Singh Darlami Tech Bouddha, 340 Shantinagar
04-25 Geek Tushal -
24,Kathman
du
0 2017- Kajol MySQ Technical 555 Vivek Ojha Tech Mcgraw Hill 230 Shantinagar
04-25 L Geek -2 -
24,Kathman
du
1 2017- Sunn Dance Skill 556 Sunny Singh Heroes Mcgraw Hill 500 baneswor-
04-25 y -1 34,Kathman
Deol du
1 2017- Sunn Sing Skill 556 Sunny Singh Heroes Mcgraw Hill 600 baneswor-
04-25 y -1 34,Kathman
Deol du
13
User_id Member_name user_type Member_hobbies username password Is_user_activ rating review
e
Now, the table is in 1NF. Now, we have identified some partial dependencies which we will
break in tables in 2NF.
Now that the table is in 1NF, we will go for 2NF in which we will remove partial
dependencies on the tables.
We will break the table purchase ((Fig: Purchase 2) into 3 tables. Purchase table will
contain purchase_id, purchase_date, order_invoice_num, order_number, book_id as
its attributes. Books table will contain book_id, book_name, book_entry_date,
publisher_id, book_category, book_author and and book_price. Publisher table will
contain publisher_id, publisher_name, publisher_add as its fields. Here we have
removed minimum anomalies of the system.
14
Table Publisher
Table Purchase
PK purchase_id
FK book_id
invoice_date
order_number
order_invoice_num
Table Book
PK book_id
FK publisher_id
book_price
book_category
book_category_code
book_entry_date
book_name
book_author
author_code
15
PK publisher_id
publisher_name
publisher_add
Since we already had made our books, publishers, category, author table during
normalization of Purchase table. So we decided to split Sales and users table to 4 tables i.e.
Sales, Members, users and review.
Table Sales
PK sales_id
FK book_id
member_id
order_date
is_delivered
sales_order_invoice_number
16
Table Member
PK member_id
FK User_id
member_fname
member_lname
member_shi_address
Table User
PK user_id
password
is_active
role_name
17
Table review
member_id
book_id
rating
review
Here, we make composite primary key of member_id and book_id as same member_id and
book_id never come together in same row as per our requirements.
In Third Normal Form(3NF), we remove every transient dependency and make its
identifier as PK. Here we further split purchase table to make it two related tables i.e.
purchase and orders. We can further make tables like:
Table Purchase
PK purchase_id
FK book_id
FK order_id
18
Table Order
PK order_id
invoice_number
FK publisher_id
Order_date
Table Book
PK book_id
FK publisher_id
book_price
category_code
book_entry_date
book_name
FK author_code
Table Author
PK author_code
book_author
19
Table Category
PK category_code
book_category
Table Sales
PK sales_id
FK book_id
member_id
20
Table Sales_order
PK sales_order_invoice_number
order_date
is_delivered
Table User
PK user_id
FK role_id
username
password
21
Table Role
PK role_id
role_name
22
After 3NF We got 12 tables for initially Purchase table. They are:
1. Purchase
2. Book
3. Publisher
4. Author
5. Category
6. Order
7. Member
8. User
9. Role
10. Review
11. sales_order
12. Sales
23
5. Database Schema
A database schema is the skeleton structure that represents the logical view of the entire
database. It defines how the data is organized and how the relations among them are
associated. It formulates all the constraints that are to be applied on the data.
A database schema defines its entities and the relationship among them. It contains a
descriptive detail of the database, which can be depicted by means of schema diagrams. The
importance of designing well-defined database schema helps programmers understand the
database and make it useful whose software will interact with the database.
(Tutorialspoint.com, 2005)
A logical database schema defines all the logical constraints that need to be apply to the
stored data. It may define integrity constraints, views and tables.
This schema pertains to the actual storage of data and its form of storage like files, indices,
etc. It defines how the data will be stored in a secondary storage. (Lucidchart.com, 2006)
24
6. Data Dictionary
Data dictionary can list all the tables and columns with their data type, limits, default values
etc.
Data dictionary is the document that describes the data both physically (number of features,
number of rows, data types, cardinality of features etc.) and more importantly logically/
semantically (how the data set was collected, what each feature is, what the condition features
are, what the decision attribute is about and how they may be related etc.)
Example:
Where ID is and identifier or person whose data is being analyzed, Age is the age of the
person in years, Gender is the gender of person with M standing for Male, F for female & U
for unknown and Height for person height in centimeters.
Since the data dictionary contains the definition of the database, it is good resource for a user
to gain information about the database. The data dictionary designed in this project document
looks similar as made up in SQL tables and views. The main important part of the data
dictionary is to understand the structure of the database as well as the dictionary as an up-to-
date reference document. (essentialsql.com, 2015)
Table User:
25
Table review:
Table Purchase:
Table order:
Table Book:
Table author:
26
Table category:
Table role:
Table publisher:
Table sales
27
Table member:
28
7. SQL Statements
There are different types of SQL statement representing various data query languages. We’ve
listed two of them below.
Data definition language (DDL) statements let a user perform these tasks:
Some of the DDL statements are: Alter, Analyze, Audit, Comment, Create, Drop, Flashback,
Grand, Purge, Rename, Revoke, Undrop etc.
Data manipulation language (DML) statements access and manipulate data in existing
schema objects. These statements do not implicitly commit the current transaction.
DML statement manipulates data and gets access in existing schema objects.
Statement cannot commit the current transaction so that it takes few changes in the
data.
It includes commands to insert, update, delete, and retrieve data within database
tables.
The select statement is a limited form of DML statement so it can only access data in
the database.
It cannot manipulate data in the database but it can operate on the accessed data.
The Call and Explain statement are only supported in SQL when it execute
dynamically.
29
Some of the DML statements are Call, Delete, Explain Plan, Insert, Lock Table, Merge, Select, and
Update etc.
/*question 1*/
select * from publisher_order order by send_date asc
/*question 2*/
same as question 1
/*question 3*/
select invoice_no, publisher_id from order_book
/*question 4*/
select * from member
/*question 5*/
select * from delivery where delivery_status='yes'
/*question 6*/
select book_category,book_id, book_name from book_details order by
book_category
/*question 7*/
SELECT book_category, COUNT(*) as count FROM book_details GROUP BY
book_category
/*question 8*/
select book_id, sum(amount) total from customer_order group by book_id
/*question 9*/
30
8. Workload Matrix
31