Вы находитесь на странице: 1из 35

GROUP ASSIGNMENT

TECHNOLOGY PARK MALAYSIA

Introduction to Databases

(CT042-3-1)

HAND OUT DATE: 10 April 2017

HAND IN DATE: 7 July 2017

WEIGHTAGE: 50%

___________________________________________________________________________

INSTRUCTIONS TO CANDIDATES:

1. Submit your assignment at the administrative counter.

2. Students are advised to underpin their answers with the use of references (Cited
using the Harvard Name System of referencing).

3. Late submissions will be awarded zero (0) unless extenuating Circumstances


(EC) are upheld.

4. Cases of plagiarism will be penalized.

5. The assignment should be bound in an appropriate style (comb bound or


stapled)

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.

7. You must obtain 50% overall to pass this module.


INTRODUCTION TO DATABASES
CT042-3-1

INTAKE CODE: NP1F1609IT


Acknowledgment

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,

Mandip Poudel (NP000083)

Shalinee Yadav (NP000094)

Sunni Singh Darlami (NP000096)

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.

1.1 Types of Database

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

An active database consists of various components, which is called an object. Below


listed are different components that are accessible in 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.

1.4 Project Aims and Objective

a. Improvement in database system.


b. Online book issue.
c. Notification of new books and materials to library manager.
d. Send invoice to account department for payment.
e. Member registration on e-library.
f. Store information about user feedback and book ratings.

3
1.5 Operation Environment

Processor Intel core processor or better performance

Operating system Microsoft Windows XP, Windows 7, Windows 8, Windows 10

Memory 1GB RAM or more

Database Application Microsoft SQL Server 2008 R2

4
2. ER Modelling

Peter Pin-Shan Chen of Massachusetts Institute of Technology (MIT) purposed ER model in


the 1970’s. The ER model defines the conceptual and graphical representation view of a
database. ER model helps the logical relationship of entities in order to create a logical
database. It works around real-world entities and the associations among them. At view level,
ER model is considered a good option for designing databases.

ER modelling of the database is portrayed as a diagram, called an entity-relationship diagram,


which defines the graphical breakdown of a sentence into its grammatical parts. An entity can
be defined by means of its properties, called attributes. Relationships are the equivalent of
verbs or associations, such as the act of purchasing, the act or repairing, being a member of a
group or being a supervisor of a department. A relationship can be defined according to the
number of entities associated with it, knows as the degree. (Rouse, 2005)

Attributes can come together in a way like

a. Simple single-valued attributes


b. Simple multi-valued attributes
c. Composite single-valued attributes
d. Composite multi-valued attributes

5
Advantage of ER model

a. Conceptually it is very simple


b. Better visual representation
c. Effective communication tool
d. It is highly integrated with relational model
e. Easy conversion to any data model

Disadvantage of ER model

a. Limited constraints and specifications


b. Loss of Information content
c. Limited relationship representation
d. No industry standard for notation
e. Popular for high-level design
f. No representation of data manipulation (Edugrabs.com, 2015)

6
3. Business Rules

 The publisher supplies the ordered books to the University warehouse.


 Purchase books online, to need initially register as members.
 Once the payment made, the customer will be able to print or save the receipts.
The store will send the books to the customers within 7working days.
 It should also store information about user opinions and book rating.
 No change is allowed; only one feedback per user per book is allowed.

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.

Normalization is use for mainly two purpose:

a. Eliminating redundancy (useless data).


b. Ensuring data dependencies make sense i.e. data is logically sorted.

Normalization used in this project are of types. These are:

a. First Normal Form(1NF)


 As per the rule of first normal form, an attribute (column) of a table
cannot hold multiple values. It should hold only atomic values.
 Every attribute must have atomic value that cannot be shorten further.
Example: Name is non-atomic attribute as it can be broken into
FirstName, MiddleName, and Surname.
b. Second Normal Form(2NF)
 An entity must be in First Normal Form
 Entity must have a Primary Key or composite Primary key
 Every attribute must be fully and functionally dependent upon Primary
key
c. Third Normal form(3NF)
 An entity must be Second Normal Form.
 There must not be any dependency among non-key attribute(other than
Primary key) (Stephens, 2003)

8
Advantages

a. Avoids data modification (INSERT/DELETE/UPDATE) anomalies as each


data item lives in One place
b. Greater flexibility in getting the expected data in atomic granular
c. Normalization is conceptually cleaner and easier to maintain and change as
your needs change
d. Fewer null values and less opportunity for inconsistency
e. A better handle on database security
f. Increased storage efficiency
g. The normalization process helps maximize the use of clustered indexes, which
is the most powerful and useful type of index available.

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:

a. Boyce Codd Name Form (BCNF)


b. Fourth Normal Form (4NF)
c. Fifth Normal Form (5NF)

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

Table: Purchase before 1NF

Before First Normal Form(1NF), our sales table looked like:

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

Table: Sales Table before 1NF

10
Before First Normal Form(1NF), our users table looked like:

User_i Member_name user_type ratings Username password Is_user_active books revie


d ws

1 Administrator Admin L8ugWdW5l 1


h6yads

2 Sunni Singh Member 9, 10 Sunni123 Chulesikodh 1 Java,p Good,


Darlami ar123 hp bad

Fig: Users review Table before 1NF

11
Above we can see unmanaged table for purchase.

 First Normal Form(1NF)

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

Fig: Purchase Table in 1NF

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

Fig: Sales Table after 1NF

13
User_id Member_name user_type Member_hobbies username password Is_user_activ rating review
e

1 Administrator admin cklhsdjfieugj 1

2 Vivek Chandra Ojha member 10 Vcojha123 skldskffdjk 1 8 Good

2 Vivek Chandra Ojha member 8 Vcojha123 skldskffdjk 1 10 Very Good

Fig: User table after 1NF

Now, the table is in 1NF. Now, we have identified some partial dependencies which we will
break in tables in 2NF.

 Second Normal Form(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

Fig: Purchase Table

Table Book

PK book_id
FK publisher_id
book_price
book_category
book_category_code
book_entry_date
book_name
book_author
author_code

Fig: Book Table

15
PK publisher_id
publisher_name
publisher_add

Fig: Publisher Table

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

Fig: Table Sales after 2NF

16
Table Member

PK member_id
FK User_id
member_fname
member_lname
member_shi_address

Fig: Member Table after 2NF

Table User

PK user_id
password
is_active
role_name

Fig: User table after 2NF

17
Table review

member_id
book_id
rating
review

Fig: Review table after 2NF

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.

 Third Normal Form (3NF)

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

Fig: Purchase table in 3NF

18
Table Order

PK order_id
invoice_number
FK publisher_id
Order_date

Fig: Order Table in 3NF

Table Book

PK book_id
FK publisher_id
book_price
category_code
book_entry_date
book_name
FK author_code

Fig: Book Table in 3NF

Table Author

PK author_code
book_author

Fig: Author Table in 3NF

19
Table Category

PK category_code
book_category

Fig: Table Category in 3NF

We also split sales table into sales and sales_order in 3NF:

Table Sales

PK sales_id
FK book_id
member_id

20
Table Sales_order

PK sales_order_invoice_number
order_date
is_delivered

Fig: Sales order table after 3N

Table User

PK user_id
FK role_id
username
password

Fig: User table after 3NF

21
Table Role

PK role_id
role_name

Fig: Role table after 3NF

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 database schema is divided into two broad categories:

5.1 Logical Database

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.

5.2 Physical Database

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:

ID Age Gender Height


1 25 M 175

Table: Example of data dictionary

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)

The tables used in this project is demonstrated below:

Table User:

S.N. Field type Length Description Example


name
1 User_id int 9 Id for user 000003
2 Password Int 9 Password for user ********
3 Is_active varchar 10 User active Yes
4 role_name int 9 Role of user Yes

25
Table review:

S.N. Field name type Length Description Example


1 member_id int 9 Membership id 001
2 Book_id Int 9 ID of book 555,553
3 rating int 10 Rating of book 8,9,10
4 review varchar 10 Review of book Good, bad

Table Purchase:

S.N. Field name type Length Description Example


1 Purchase- int 9 Id for individual order 1,2
id(PK)
2 Book_id(FK) Int 9 ID of book 555, 553
3 Order_id Int 100 Id of ordered java

Table order:

S.N. Field name type Length Description Example


1 Order_id(PK) int 9 Id of order 001
2 Invoice_number Int 9 No of invoice 3456
3 Publise_id(FK) varchar 10 Id of publisher 002
4 Order_date date Date of order 06/07/2016

Table Book:

S.N. Field name type Length Description Example


1 Book_id(FK) int 9 Id of book 555, 553
2 Publisher_id(FK) Int 9 ID of publisher 002
3 Book price money 100 Price of book 1000
4 Category_code int 9 Category code of books 2
5 Book_entry_date date Book entry date 09/08/2015
6 Book_name varchar 10 Name of book java
7 Author_code(FK) varchar 10 Code to recognize author 0076

Table author:

S.N. Field name type Length Description Example


1 Author_code varchar 9 Code to recognize author 0076
2 Book_author varchar 9 Author of book Parash kant

26
Table category:

S.N. Field name type Length Description Example


1 Category_code int 9 Category of code 2
2 Book_category Int 9 Category of book 5

Table Sales order:

S.N. Field name type Length Description Example


1 Sales_order_invoice_number int 10 Invoice for sales order 4568
2 Order_date date Date of order 06/07/2017
3 Is_delivered varchar 9 Delivery of book Yes, No

Table role:

S.N. Field name type Length Description Example


1 role_id int 9 Id of role 008
2 Role_name vachar 9 Role name Yes, No

Table publisher:

S.N. Field name type Length Description Example


1 Publisher_id(PK) int 9 Id of publisher 02
2 Publisher_name varchar 9 Publisher name Pearson’s
3 Publisher_add varchar 10 Add of publisher

Table sales

S.N. Field name type Length Description Example


1 Sales_id(PK) int 9 Id of sales 009
2 Book_id Int 9 ID of book 555,553
3 Member_id int 10 Id of member 008
4 Order_id int 9 Id of order 08
5 Is_delivered varchar 10 Delivered is done or not Yes, No
6 Sales_order_invoice Int 10 Invoice of sales order 6574

27
Table member:

S.N. Field name type Length Description Example


1 Member_id(PK) int 9 Id of member 008
2 User_id(FK) Int 9 ID of user 00003
3 Member_fname varchar 30 First name of member Ram
4 Member_lname varchar 30 Last name of member Singh
6 Member_shi_add varchar 10

28
7. SQL Statements

There are different types of SQL statement representing various data query languages. We’ve
listed two of them below.

7.1 Data Definition Language (DDL)

Data definition language (DDL) statements let a user perform these tasks:

 Create, alter and drop schema objects


 Grand and revoke privileges and roles
 Analyze information on a table, index or cluster
 Establish auditing options
 Add comments to the data dictionary

Some of the DDL statements are: Alter, Analyze, Audit, Comment, Create, Drop, Flashback,
Grand, Purge, Rename, Revoke, Undrop etc.

7.2 Data Manipulation Language (DML)

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.

The SQL statements and queries in the project is shown below:

/*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

select * 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*/

select book_id, avg(rating) score from feedback


order by score asc

30
8. Workload Matrix

Student Name Allocation of Signature


Work Percent

S1. Mandip Poudel (NP000083) 34%

S2. Shalinee Yadav (NP000094) 33%

S3. Sunni Singh Darlami 33%


(NP000096)

31

Вам также может понравиться