Group Assignment: Technology Park Malaysia CT042-3-1-IDB Introduction To Database NP1F1609IT

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

\

GROUP ASSIGNMENT
TECHNOLOGY PARK MALAYSIA
CT042-3-1-IDB
INTRODUCTION TO DATABASE
NP1F1609IT
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 DATABASE
CT042-3-1-IDB
Group-4

INTAKE CODE: NP1F1609IT

SUBMITTED BY
Uday Kumar Sah (NP000097)
Amar Bahadur Bogati (NP000077)

Abhishek Negi (NP000075)


Table of Contents
1. Introduction of the database .................................................................................................................. 1
1.1. Components of Database System....................................................................................................... 1
1.1.1 Software ....................................................................................................................................... 1
1.1.2. Hardware ..................................................................................................................................... 1
1.1.3. Data ............................................................................................................................................. 1
1.1.4. Procedures ................................................................................................................................... 2
1.1.5. People.......................................................................................................................................... 2
1.2. Objective ............................................................................................................................................ 2
1.3. Types of Database .............................................................................................................................. 2
1. Relational Database........................................................................................................................... 2
2. Database Warehouse ......................................................................................................................... 3
3. Operational Database ........................................................................................................................ 3
4. Distributed Database ......................................................................................................................... 3
5. End-User Database............................................................................................................................ 3
6. Centralized Database......................................................................................................................... 4
7. Commercial Database ....................................................................................................................... 4
2. Entity Relationship Modeling (ED) .......................................................................................................... 5
3. Business Rules .......................................................................................................................................... 6
4. Normalization Process .............................................................................................................................. 6
4.1. Types of Normalization ..................................................................................................................... 6
4.1.1. First Normal Form .......................................................................................................................... 6
Limitation of First Normal Form. ......................................................................................................... 7
4.1.2 Table of Second Normal Form......................................................................................................... 8
Limitation of Second Normal Form ...................................................................................................... 8
4.1.3. Third Normal Form ......................................................................................................................... 9
5. Database Schema/Diagram ..................................................................................................................... 10
5.1. Database Hierarchical Schema......................................................................................................... 10
5.2. Table schema.................................................................................................................................... 11
6. Data Dictionary ....................................................................................................................................... 18
6.1. Table Name 1:-publisher_details ..................................................................................................... 18
6.2. Table Name 2:-newbook_details ..................................................................................................... 18
6.3. Table Name 3:-book_details ............................................................................................................ 19
6.4. Table Name 4:-customer_details ..................................................................................................... 19
6.5. Table Name 5:-sendorder_details .................................................................................................... 20
6.6. Table Name 6:-sales_information .................................................................................................... 20
6.7. Table Name 7:-delivery_information............................................................................................... 21
6.8. Table Name 8:-bill_details ............................................................................................................... 21
6.9. Table Name 9:-opinion .................................................................................................................... 22
7. SQL Statement ........................................................................................................................................ 22
7.1. Data Definition Language (DDL) .................................................................................................... 22
7.1.1. Create ........................................................................................................................................ 22
7.1.2. Alter .......................................................................................................................................... 24
7.1.3.Drop ............................................................................................................................................... 25
7.2. Data Manipulation Language (DML) .............................................................................................. 25
7.2.1. Select ......................................................................................................................................... 25
7.2.2. Update ....................................................................................................................................... 26
7.2.3. Insert ......................................................................................................................................... 26
7.2.4. Delete ........................................................................................................................................ 26
7.3. SQL Commands ............................................................................................................................... 27
/* Question 1*/ .................................................................................................................................... 27
/*Question 2*/ ..................................................................................................................................... 27
/*Question 3*/ ..................................................................................................................................... 28
/*Question 4*/ ..................................................................................................................................... 28
/*Question 5*/ ..................................................................................................................................... 29
/* Question 6*/ .................................................................................................................................... 29
/*Question 7*/ ..................................................................................................................................... 30
/*Question 8*/ ..................................................................................................................................... 30
/*Question 9*/ ..................................................................................................................................... 30
Conclusion .................................................................................................................................................. 31
Workload Matrix......................................................................................................................................... 32
References ................................................................................................................................................... 33
E-Bookstore

1. Introduction of the database


A database is a collection of related data. The main purpose of making database as accessed
multiple user at a time. Database are generally categorized into application purpose. For Example,
one database may contains student related information (publisher_id, publisher_FirstName,
publisher_Address) data; another may contain, customer data; another may contains, purchase
related data, and so on. Database system managed by Database management systems. (C.S, n.d.)

1.1. Components of Database System


1. Software
2. Hardware
3. Data
4. Procedures
5. People

1.1.1 Software
Software is a set of program that used to control better way to manage overall data in the
Database management system (DBMS), the operating system, network software that work as
integration form and give as possible best output of users. And also Application program that
needs for access data in the Database Management System.

1.1.2. Hardware
Hardware is set of physical electronics devices such as computer I/O Devices, Storages
devices that help to provide give a way to excess interface between database and users hardware
components, its major part of database that physically exists.

1.1.3. Data
Data is raw fact. And it most important part of Database management system (DBMS).its
help to make information and information is most important part for decision making. The database
contains both actual or operational data and the metadata.

1
E-Bookstore

1.1.4. Procedures
Procedures is instruction and set of rules and constrains that assists and gives a way to how
to use database management system (DBMS) and in designing and running the database.
Procedures is guidelines for user’s or manager that operates the database.

1.1.5. People
People is person who interact with database management System (DBMS) who need
information about according to decision making on the basis of job which types of information are
provided may be decided by Database Admistrator .people is actually manage or collect
information database. For example: - Staff, Manager, (dataentryoutsourced, n.d.)

1.2. Objective
1. Make Shareability
2. Combining inter-related data
3. Make efficient way to manage data.
4. Controlling Concurrent updates so as to maintain data integrity (management-hub.com,
n.d.)

1.3. Types of Database


1. Relational Database
2. Database Warehouse
3. Operational Database
4. Distributed Warehouse
5. End-User Database
6. Centralized Database
7. Commercial Database

1. Relational Database
This database stored in various data tubes. Each table has a key field which is used to connect it to
other tubes. Hence all the tables are related these database is extensively used various industries

2
E-Bookstore

and will be the one you are most likely to come across when working in information Technology
(IT).

Some example of relational databases are Sybase and Microsoft SQL Server, Oracle. In this
database process software deployment part included in program. So you can easily project when
creating a project plan and estimating project costs.

2. Database Warehouse
Database Warehouse is important part of organization of organization to achieve any kind’s
information of the several years. Information is very information recover as losses data. Data ware
house is a database is to keep all relevant data for several years. It can be as long as 6 years later.
The data is also an important source of information for analyzing and comparing the current year
data with that of the past years. Which also make it easier to determine key trends taking place.
All the data from previous years are stored in a database warehouse.

3. Operational Database
In this modern technology, operational database is play big role of daily to daily operation of
organizational. Thing of such as inventory management, purchase, financial and transactional. All
data is collected in a database which is often know by several names such as operational /
production database or transactional data.

4. Distributed Database
Some multinational company and organization has several department and branches. Each of these
has their individual database. And collected data as a various geographical disperse and save data
as regional database is known as Distributed. Each of these work group may have their own
database which together will form the main database of the company. This is also distributed
database.

5. End-User Database
In this planet there are different types of database existing .among one of them as us End user
database. Some of database stored as data spreadsheets, presentations, work files, notepad and
others files. This small database form as different types of database called the end-user database.
(My Project Management Expert., n.d.)

3
E-Bookstore

6. Centralized Database
Centralized database is a type of database the keeps all data in a single database system signal
machine called a database server hosts the DBMS and the Database. (omsar, n.d.)

7. Commercial Database
The database to be access is provided to users as a commercial venture is called on commercial or
external database. These types of database making purpose as serves information of external users.
These database are subjected specific and access to these database is sold as a paid services to its
user. There are many commercial database services as available particularly in the area of financial
and technical information.

These commercial database uses as statistics commodity, foreign exchange and stock market ,
companies and their performance important and their buying pattern decided can law’s etc. the
access to commercial database may be given thought communication links . (S, n.d.)

4
E-Bookstore

2. Entity Relationship Modeling (ED)


An entity relationship diagram (ERD) shows the relationship of entity sets stored in a
database , an entity in the context is a component of data .in other word to be say ER diagram
illustrate the logical structure of database at first glanced an entity relationship diagram looks very
much like a flowchart . It is the specialized symbols and the, meanings of those symbols that make
to be unique.in this APU’s E-Bookstore Project ERD of entity. (smartdraw, n.d.)

Advantage of Entity Relationship Diagram

1. Conceptually it is very simple


2. Better visual representation
3. Effective communication tools
4. Highly integrated with relational model (EduGrabs, 2015)

book_categ
quantity
ory

book_id

book_id publisher_i
book_details d

export_stat
us

M
quantity Check Sended
books

Send book_details publisher_


export_dat
e phone
delivery_infor
mation M
publisher_i
customer_i M d
d
Give Delivery Book 1 M
information publisher_det publisher_
Publisher's New Book M
ais name

publisher_a
1 ddress
1

M
M publisher_c
Rating of per book
customer_i ountry
d
Avalialbe book check
1
Delivery
feedback
Have Invoice
Place order

feedback_d
opinion
ate
1
M
Give feedback M
rating
IS_paid
M
1

Store Information invoice_dat


customer_det about Invoice e
ails M bill_details

1
M
publisher_i
d
Give Invoice sendorder_det
M publisher_i
ails
d

invoice_id
book_id

quantity

Payment
quantity
order_date

1
book_id
invoice_id

customer_
ContactNo

sales_informa
Customer_
tion
Address customer_
invoice_id IS_Mmber customer_ customer_id
LastName FirstName

transaction transaction payment_t


invoice_id IS_paid
_id _date ype

Figure: - Entity Relationship Diagram

5
E-Bookstore

3. Business Rules
1. The supplied books are kept in the university warehouse.
2. An invoice must be send into Account Department.
3. Customer who wish to purchase books online, needs initially register’s as member.
4. Once the complete payment, the customer will able to be print or save the receipts.
5. The store will send the books to the customer within 7 working days.
6. Users can also provide feedback for a book.as a score 1-10 (which 0= means terrible
10=masterpiece) along with the optional short text. No change are allowed; only one
feedback per user per book is allowed.

4. Normalization Process
Database Normalization is a technique of organization the data in the database. Normalization is a
systematic approach of decomposing tables to eliminate data redundancy and undesirable
characteristics like insertion, Update, Deletion Anomalies. It is a multi-step process that puts data
into tabular form by removing duplicated data from the relation tables.

Normalization is used for mainly two process,

1. Eliminating redundant (useless) data.

2. Ensuring data dependencies make sense i.e. data is logically stored.

4.1. Types of Normalization


1) First Normal Form
2) Second Normal Form
3) Third Normal Form

(studytonigh, n.d.)

4.1.1. First Normal Form


As per First Normal form, no two rows of data must contain repeating group of information i.e.,
each set of column must have a unique value not as automic values content as a single column,
such that multiple column cannot be used to fetch the same row. Each table should be organized
into rows, and each row should have a primary key that distinguishes it as unique. The primary

6
E-Bookstore

key is usually a single column, but sometimes more than one column can be combined to create a
single primary key. For example consider a table which is not in First normal form.

Limitation of First Normal Form.


1. Translating a table into 1NF alleviates much of the data redundancy and wasted space of a
table that has not been normalized.

1. First Normal form is only a first step to good design. It’s still possible for a table in 1 NF to be
designed inefficiently. (relationaldbdesign, 2017)
1NF Key
Table of 1NF
Table 1
customer_id P.K
book_id P.K
invoice_id P.K
publisher_id P.K
customer_FirstName
customer_LastName
customer_Address
customer_ContactNo
quantity
feedback
rating
feedback_date
export_status
Is_member
book_category
book_name
book_rate
book_author
ISBN
send_date
order_date
publisher_name
publisher_address
publisher_phone
publisher_country
transaction_id
transaction_date
payment_type
invoice_date
Is_paid

Figure 1:- First Normal Form

7
E-Bookstore

4.1.2 Table of Second Normal Form


As per the second normal form there must be any partial dependency of any column on primary
key. Its means that for a table that has concatenated key for its existence. If any column depends
only on one part of the concatenated key. Then the table fails second Normal form

Limitation of Second Normal Form


1. There are one insertion anomaly. You cannot insert data about a publisher until you have an
item from that publisher.

2. There is one deletion anomaly: if you delete the only item from a publisher, you lose data about
the publisher

3. There is also a modification anomaly. The publisher id is duplicated for every order where they
sends. (relationaldbdesign, 2017)

2NF Key 2NF key 2NF key


Table 1 Table 2 Table 3
publisher_id P.K customer_id P.K invoice_id F.K
invoice_id P.K book_id F.K transaction_id
book_id P.K invoice_id F.K transaction_date
customer_FirstName Is_paid
publisher_name
customer_LastName payment_type
publisher_address customer_Address
publisher_phone customer_ContactNo
publisher_country quantity
invoice_date Is_member
export_date
Is_paid
export_satus
Quantity
feedback
book_category rating
order_date feedback_date
book_name
book_rate
book_author
ISBN
send_date Figure 2:- Second Normal Form

8
E-Bookstore

4.1.3. Third Normal Form


Third normal form applies that every non-prime attributes of table must be dependent on primary,
or we can say, there should not be the case that a non-prime attributes is determined by another
non-prime attributes. So the transitive functional dependency should be removed from the table
and also the table must be in Second Normal Form (2NF).

3NF Key 3NF Key 3NF Key


publisher_details sendorder_details book_details
publisher_id P.K invoice_id P.K publisher_id F.K
publisher_name publisher_id F.K book_id F.K
publisher_address book_id F.K quantity
publisher_phone order_date book_category
publisher_country book_category

3NF key
3NF Key
bill_details sales_information
3NF Key
publisher_id F.K invoice_id F.K
newbook_details
book_id P.K invoice_id F.K transaction_id
invoice_date transaction_date
publisher_id F.K
Is_paid Is_paid
book_category payment_type
book_name
book_rate
book_author
ISBN 3NF key
Send_date opinion 3NF key
customer_id F.K customer_detail
book_id F.K customer_id P.K
feedback invoice_id F.K
3NF key rating book_id F.K
delivery_information feedback_date customer_FirstName
book_id F.K customer_LastName
customer_id F.K customer_Address
export_date customer_contactNo
Quantity quantity
export_status Is_member

Figure 3:- Third Normal Form Tables

(Database Technology, 2017)

9
E-Bookstore

5. Database Schema/Diagram
5.1. Database Hierarchical Schema

Publisher

Conceptual Logical Physical


Schema Model Data
Model

Member

E-Book store Database Schema Model/


Manager Diagram

1. External Model

End user’s view of the data environment and its required that the modeler subdivide set of
requirement and constraints into functional modules that can be examined within the framework
of their external models. In this figure Publisher, Customer, E-bookstore manager is main
perspective of Interact with system so it’s External data Model

2. Conceptual / Logical Model

Conceptual and logical Model determine to the global view of the database and its
represents of data viewed by the entire organization. A basis for identification and high- level
description of main data objects, avoiding details. Its most widely used conceptual model is an
entity relationship diagram (ER) Model.

10
E-Bookstore

3. Internal Model

In this internal model as represented of the database as “Seen” by the DBMS (Database
management system) and maps of the conceptual model to the specific representation of an internal
model and it is hardware in depended and its lower stages as physical model .and it’s also as
physical model .its operates as lowest level of abstraction of database. (Lai Chew Ping, 2017)

5.2. Table schema

Fig:- bill details

This table of Bill details, here is used field name is invoice_id and publisher_id whose data type
is integer whose length is 4, here is used Foreign key in publisher_id and invoice_id also used
Not Null constant. In invoice_date its data type is date here is also used not null constant.
Is_paid is also a field name its data type is varchar.

11
E-Bookstore

Fig:- book details

This is the table of book details where field name is book_id, publisher_id, quentity and
book_category etc. In fileld name book_id, publisher_id, quantity here data type is intiger also
uses Not Null constant. book_category its data type is varchar its data length is 10. In the table
in field book_id and publisher_id here is used forign key.

Fig:- customer details

12
E-Bookstore

This is the table of customer details where field name is customer_id, customer_FirstName,
customer_LastName, customer_Address, customer_contact, book_id, invoice_id and
quantity etc. In field name customer_country, customer_firstName, customer_LastName and
customer_Address here is used Not Null constant its data length is 4. In the customer_id here is
used Primary key. And in book_id and invoice_id here is used forign key and also used Not
Null constant.

Fig:- delivery information

This is the table of delivery informatiom where is used forign key in book_id and customer_id.
In the field name extort_data here data type is data and export_status data type is varchar and
other field names data type is intiger. Excluding the export_status there is used Not Null
constant.

13
E-Bookstore

Fig:- newbook details

In the table of newbook details here is used Primary key in book_id and forign key is used in
publisher_id. The field name book _category, book_name, book_author and ISBN here is
used varchar. In this table here is also used Not Null constant.

Fig:- opinion

14
E-Bookstore

In the table opinion here is used forign key in customer_id and book_id here is also used
NotNull constant. Here used data type name are varchar, intiger and date etc. The table field
names are customer_id, book_id, feedback, rating and feedback_date.

Fig:- publisher details

In the table of publisher_datails here is used Primary key in publisher_id here is also used Not
Null constant. Here used field names are publisher_id, publisher_name, publisher_address,
publisher_phone and publisher_country.

Fig:- sales informatiom

15
E-Bookstore

This is the table of sales information here is used forign key in invoice_id. And transaction_id,
transaction_date, invoice_id, Is_paid and payment_type this all are the fields names. Here
used data type are varchar, intiger and date. Here is also used Not Null constant.

Fig:- sender details

In the table of sender details here is used both Primary key and Forign key. Primary key is used
in invoice_id and Forign key is used in book_id and publisher_id. Here is also used Not Null
constant in all the fields. Here used fields name are book_id, publisher_id, quantity,
order_date, and invoice_id.

16
E-Bookstore

Fig:- Bill details

This table of Bill details, here is used field name is invoice_id and publisher_id whose data type
is integer whose length is 4, here is used Not Null constant. In invoice_date its data type is date
here is also used not null constant. Foreign key in publisher_id and invoice_id.

17
E-Bookstore

6. Data Dictionary
6.1. Table Name 1:-publisher_details

Field Data Type Domain Description Types of Example Link as


Constrains P.K
publisher_id Integer - Code name of Not null 101
Publisher ,Unique,
P.K
publisher_name Varchar 20 Name of Not null Saraswati
Publisher Stationary
publisher_address Varchar 30 Permanent Not null Kathmandu
Address of
Publisher
publisher_phone Varchar 10 Publisher Not null, 9804810249
unique phone unique
nu
publisher_country Varchar 30 Publisher Not null Nepal
country name

6.2. Table Name 2:-newbook_details


Field Data Domain Description Types Example Link as P.K
Type of Key
book_id Integer - Code name of Not 153
Book null,
Unique,
P.K
publisher_id Interger 5 Code name of Not 101 Publisher_details
Publisher null, (publisher_id)
F.K
book_category Varchar 10 Category of Not Comedy
Book Null
book_name Varchar 50 Name of Not Funckey
Book null,
book_rate Money 8 Book Per unit Not null 205
Price
book_author Varchar 30 Writer of Not null Devil cal
Book
ISBN Integer 13 International Not null 1324567563456
Standard
Book Number
send_date Date - Publisher - 6/7/2017
latest book list
sended by e-
book manager

18
E-Bookstore

6.3. Table Name 3:-book_details


Field Data Domain Description Types Example Link as P.K
Type of Key
book_id Integer - Code name F.K 153 newbook_details(book_id)
of Book
publisher_id Integer - Code Name F.K 101 publisher_details(publisher_id)
of
Publisher
quantity Integer - Unit of - 6
Booked
order
book_category Varchar 10 Under - comedy
category of
books

6.4. Table Name 4:-customer_details


Field Data Domain Description Types Example Link as P.K
Type of Key
customer_id Integer Customer Not 156
Identity null,
Number Unique,
P.K
customer_FirstName Varchar 20 Customer - Uday
First Name
customer_LastName Varchar 20 Customer - Sah
Last Name
customer_Address Varchar 30 Customer Not Jadibuti-35
Address null
customer_ContactNo Varchar 10 Customer - 9813151323
Phone
Number
book_id Integer - Unique F.K 153 newbook_details(book_id)
book
idebtity no
invoice_id Integer - unique Not 1050
invoice null,
identity Unique
Number
quantity Integer 4 Unit of 6
Book order
by
Customer
Is_member Varchar 8 member or Not member
customer null
,check

19
E-Bookstore

6.5. Table Name 5:-sendorder_details

Field Data Domain Description Types Example Link as P.K


Type of Key
invoice_id Integer - unique Not 1050
invoice null,
identity Unique,
Number P.K
book_id Integer - Code name F.K 153 newbook_details(book_id)
of book
publisher_id Integer - Code name F.K 101 publisher_details(publisher_id)
of Publisher
order_date Date - Send order 29-06-
Date 2017
quantity Integer 4 Unit of 6
Book order
by
Customer

6.6. Table Name 6:-sales_information

Field Data Domain Description Types Example Link as P.K


Type of
Key
transaction_id Integer - Customer Not 789
Order null
Identity
Number
invoice_id Integer - invoice Not 1050 sendorder_details(invoice_id)
Identity Null,
Number F.K
transaction_date Date - Transaction Not 6/6/2017
Date null
Is_paid Varchar 6 Paid or check paid
Unpaid
payment_type Varchar 4 Visa or check Visa
Cash

20
E-Bookstore

6.7. Table Name 7:-delivery_information

Field Data Domain Description Types Example Link as P.K


Type of Key
book_id Integer - Code Name Not 153 newbook_details(book_id)
of Book null,
F.K
customer_id Integer - Customer Not 501 customer_details(customer_id)
Identity Null,
Number F.K
export_date Date - Delivery Not 6/7/2017
Date null
quantity Integer 4 List of Not 4
Book null
Ordered
export_status Varchar 3 Yes or No Check yes

6.8. Table Name 8:-bill_details

Field Data Domain Description Types Example Link as P.K


Type of
Key
publisher_id Integer - Code name Not 101 publisher_details(publisher_id)
of Publisher null,
F.K
invoice_id Integer - invoice F.K 1050 senorder_details(invoice_id)
Identity
Number
invoice_date Date - invoice - 6/7/2017
issue date
Is_paid Varchar 6 Paid or Check Paid
unpaid

21
E-Bookstore

6.9. Table Name 9:-opinion

Field Data Domain Description Types Example Link as P.K


Type of
Key
customer_id Integer - Customer Not 501 customer_details(customer_id)
Identity null,
Number F.K
book_id Integer - Code Name F.K 153 newbook_details(book_id)
of Book
feedback Varchar 200 Your Not is nice
opinions Null book
rating Varchar 2 Give your check 5
Rating rang
as 1-10
feedback_date Date - Feedbook - 6/7/2017
issues date

7. SQL Statement
7.1. Data Definition Language (DDL)
Data definition language is a standard for command that defines the different structures in
a database. Data definition language (DDL) statements Create, Modify, and Remove
database. Object such as tables, Indexes, and users. Common DDL Statement are create,
Alter and Drop. (Rouse, n.d.)

7.1.1. Create
1. create table publisher_details(publisher_id int not null primary key, publisher_name
varchar(50) not null, publisher_address varchar(50) not null,
publisher_phone varchar(10) unique not null, publisher_country varchar(30) not null)

2. create table newbook_details(book_id int primary key, publisher_id int, book_category


varchar(10),book_name varchar(50), book_rate money,
book_author varchar(30), ISBN varchar(13),send_date date,foreign key(publisher_id)
references publisher_details(publisher_id))

22
E-Bookstore

3. create table customer_details(customer_id int not null primary key,customer_FirstName


varchar(20),customer_LastName varchar(15),
customer_Address varchar(30),Customer_ContactNo varchar(10),book_id int, invoice_id
int not null, quantity int,Is_member varchar(8),
foreign key(book_id) references newbook_details(book_id))

4. create table book_details(book_id int, publisher_id int, quantity int,book_category


varchar(10),
foreign key(publisher_id) references publisher_details(publisher_id), foreign
key(book_id) references newbook_details(book_id))

5. create table sendorder_details(book_id int,publisher_id int,quantity int,order_date


date,invoice_id int not null primary key,
foreign key(book_id) references newbook_details(book_id),foreign key(publisher_id)
references publisher_details(publisher_id))

6. create table bill_details(invoice_id int,publisher_id int,invoice_date date,Is_paid


varchar(6),
foreign key(invoice_id) references sendorder_details(invoice_id),foreign
key(publisher_id) references publisher_details(publisher_id))

7. create table sales_information(transaction_id int , invoice_id int, transaction_date date


not null,
Is_paid varchar(6) not null, payment_type varchar(4) not null,
foreign key(invoice_id) references sendorder_details(invoice_id))

8. create table delivery_information(book_id int, customer_id int,quantity int,export_date


date not null,
export_status varchar(3), foreign key(book_id) references newbook_details(book_id),
foreign key(customer_id) references customer_details(customer_id))

23
E-Bookstore

9. create table opinion(customer_id int, book_id int, feedback varchar(200), rating


varchar(2),
feedback_date date,foreign key(book_id) references newbook_details(book_id),
foreign key(customer_id) references customer_details(customer_id))
7.1.2. Alter

1. ALTER TABLE customer_details WITH CHECK


ADD check (
(Is_member = 'member')
OR
(Is_member = 'customer')
)

2. ALTER TABLE bill_details WITH CHECK


ADD check (
(Is_paid = 'paid')
OR
(Is_paid = 'unpaid')
)

3. ALTER TABLE sales_information WITH CHECK


ADD check (
(Is_paid = 'paid')
OR
(Is_paid = 'unpaid')
)

4. ALTER TABLE sales_information WITH CHECK


ADD check (
(payment_type= 'visa')
OR
(payment_type= 'cash')
)

5. ALTER TABLE delivery_information WITH CHECK


ADD check (

24
E-Bookstore

(export_status='yes')
OR
(export_status='no')
)

6. ALTER TABLE opinion WITH CHECK


ADD check (
(rating > 1)
OR
(rating >= 10)
)

7.1.3.Drop

1. drop database E_bookstore

7.2. Data Manipulation Language (DML)


Data manipulation language (DML) is a family of computer languages. Including commands
permitting user.to manipulate data in a database. The manipulation involves inserting data into
database tables. Retrieving existing data, deleting data form existing tables and modifying existing
data. DML is mostly incorporated in SQL Database.

Major Commands of Data Manipulation Language

7.2.1. Select
1.1. select *from publisher_details
1.2. select *from book_details
1.3. select *from newbook_details
1.4. select *from sendorder_details
1.5. select *from bill_details
1.6. select *from delivery_information
1.7. select *from customer_details
1.8. select *from sales_information
1.9. select *from opinion

25
E-Bookstore

7.2.2. Update
The command modifies data of one or more records. An update command syntax is update[table
name] set [column name=value] where [condition].

7.2.3. Insert
a. insert into publisher_details values(101,'Saraswati
Stationary','Kathmandu','9804810249','Nepal')
b. insert into newbook_details values(153,101,'Comedy','funckey',205,'Devil
cal','1324567563456','6/7/2017')
c. insert into customer_details
values(501,'Uday','Sah','Jadibuti','9813151323',153,1050,4,'member')
d. insert into book_details values(153,101,6,'Comedy')
e. insert into sendorder_details values(153,'101','6','6/7/2017','1050')
f. insert into bill_details values(1050,101,'6/7/2017','paid')
g. insert into sales_information values(789,1050,'6/07/2017','paid','visa')
h. insert into delivery_information values(153,501,4,'6/7/2017','yes')
i. insert into opinion values(501,153,'this is great book','8','6/7/2017')

7.2.4. Delete
This command is mostly used for removes one or more records from a table according to specified
conditions. Delete command syntax is delete from[table name] where [condition] (techopedia, n.d.)

26
E-Bookstore

7.3. SQL Commands

/* Question 1*/

select
publisher_details.publisher_id,newbook_details.book_id,book_name,month=datename(MONTH
,send_date)
from publisher_details,newbook_details where
publisher_details.publisher_id=newbook_details.publisher_id

output

/*Question 2*/

select
sendorder_details.publisher_id,publisher_details.publisher_name,newbook_details.book_id,
newbook_details.book_name,sendorder_details.quantity,newbook_details.book_rate,
sendorder_details.invoice_id,month=datename(MONTH,sendorder_details.order_date)
from sendorder_details
inner join newbook_details on sendorder_details.book_id=newbook_details.book_id
inner join publisher_details on sendorder_details.book_id=publisher_details.publisher_id
output

27
E-Bookstore

/*Question 3*/

select bill_details.invoice_id,bill_details.invoice_date,
publisher_details.publisher_name,publisher_details.publisher_address,
totalamount=(sendorder_details.quantity* newbook_details.book_rate)
from bill_details
inner join publisher_details on bill_details.publisher_id=publisher_details.publisher_id
inner join sendorder_details on sendorder_details.invoice_id=bill_details.invoice_id
inner join newbook_details on newbook_details.book_id=sendorder_details.book_id
where Is_paid='unpaid'

output

/*Question 4*/

select customer_id,customer_FirstName,customer_LastName,customer_address,
customer_ContactNo from customer_details where Is_member="Is_member"

output

28
E-Bookstore

/*Question 5*/

select
delivery_information.customer_id,customer_details.customer_FirstName,customer_LastName,
customer_address,customer_ContactNo,delivery_information.book_id,newbook_details.book_na
me,delivery_information.export_date,
delivery_information.export_status
from customer_details
inner join delivery_information on
customer_details.customer_id=delivery_information.customer_id
inner join newbook_details on delivery_information.book_id=newbook_details.book_id
where export_status="export_status"

output

/* Question 6*/
select
newbook_details.book_category,sendorder_details.book_id,newbook_details.book_name,sendor
der_details.quantity
from sendorder_details
inner join newbook_details on sendorder_details.book_id=newbook_details.book_id
where book_category='horror'
output

29
E-Bookstore

/*Question 7*/
select newbook_details.book_category,count(*) as TotalNo_of_Books from newbook_details
where book_id in (select distinct book_id from bill_details)group by
newbook_details.book_category
output

/*Question 8*/
select SUM(sendorder_details.quantity) as
TotalBooks,sum(sendorder_details.quantity*book_rate) as TotalPrice
from sendorder_details join newbook_details on
newbook_details.book_id=sendorder_details.book_id
output

/*Question 9*/

select opinion.book_id,newbook_details.book_name,opinion.rating from opinion,book_details


where opinion.book_id=book_details.book_id
order by rating asc
output

30
E-Bookstore

Conclusion
This project is main motto is all about complete a database structure of APU E-Bookstore. And
finally we are completed those task which is necessary for this project. We gain a lots of knowledge
that help us to complete this assignment project. This database design is helpful for making APU
E-bookstore and we are appreciated in this database we are included all those technique that help
easily data transmission and redundancy and anomalies free database.

31
E-Bookstore

Workload Matrix

Name Work Percentage Signature

Uday Kumar Sah 50%

Amar Bahadur Bogati 50%

Abhishek Negi 0%

32
E-Bookstore

References
C.S, n.d. http://www.cs.ubc.ca. [Online]
Available at: http://www.cs.ubc.ca/nest/dbsl/intro.html
[Accessed 06 july 2017].

Database Technology, 2017. http://www.studytonight.com. [Online]


Available at: http://www.studytonight.com/dbms/database-normalization.php

dataentryoutsourced, n.d. https://www.dataentryoutsourced.com. [Online]


Available at: https://www.dataentryoutsourced.com/blog/components-of-a-database-management-
system/
[Accessed 06 july 2017].

EduGrabs, 2015. http://www.edugrabs.com. [Online]


Available at: http://www.edugrabs.com/advantages-and-disadvantages-of-er-model/
[Accessed 15 july 2017].

Lai Chew Ping, S. L., 2017. Advance Data Modeling. Kulalampur Malaysia: APU.

management-hub.com, n.d. http://www.management-hub.com. [Online]


Available at: http://www.management-hub.com/database-management-objectives.html
[Accessed 06 july 2017].

My Project Management Expert., n.d. http://www.my-project-management-expert.com. [Online]


Available at: http://www.my-project-management-expert.com/different-types-of-databases.html
[Accessed 09 july 2017].

omsar, n.d. http://www.omsar.gov.lb. [Online]


Available at: http://www.omsar.gov.lb/ictsg/01.%20OMSAR%20ICT%20Standards%20-
%20Web%20Help%20Files/Web%20Help%20Folders/104%20-%20DB%20WebHelp/104_-
_DB_Help.htm#6.1_Centralized_Databases.htm
[Accessed 09 july 2017].

relationaldbdesign, 2017. http://www.relationaldbdesign.com. [Online]


Available at: http://www.relationaldbdesign.com/relational-database-analysis/module3/limitations-1st-
normal-form.php

Rouse, M., n.d. http://whatis.techtarget.com. [Online]


Available at: http://whatis.techtarget.com/definition/Data-Definition-Language-DDL
[Accessed 07 july 2017].

33
E-Bookstore

smartdraw, n.d. https://www.smartdraw.com. [Online]


Available at: https://www.smartdraw.com/entity-relationship-diagram/
[Accessed 06 july 2017].

S, S., n.d. http://www.yourarticlelibrary.com. [Online]


Available at: http://www.yourarticlelibrary.com/database/database-six-important-types-of-databases-
business-management/10375/
[Accessed 09 july 2017].

studytonigh, n.d. http://www.studytonight.com. [Online]


Available at: http://www.studytonight.com/dbms/database-normalization.php
[Accessed 07 july 2017].

techopedia, n.d. https://www.techopedia.com. [Online]


Available at: https://www.techopedia.com/definition/1179/data-manipulation-language-dml
[Accessed 07 july 2017].

34

You might also like