DBMS Lab Manual Lab 1 To 7
DBMS Lab Manual Lab 1 To 7
OF
SCIENCE AND TECHNOLOGY
(SZABIST)
Lab Manual
J
1) Stage (Journey inside-out the concept)
2) Stage a1(Apply the learned)
3) Stage v(Verify the accuracy)
4) Stage a2(Assess your work)
1
Table of Contents
Lab # Topics Covered Page #
2
LAB # 01
Statement Purpose:
Demonstrate Installation and give introduction of MYSQL Workbench which will be used in
later labs during semester.
Activity Outcomes:
Installation of MYSQL Workbench on students Laptops/Lab Systems
Instructor Note:
Discussion with students regarding installation issues and troubleshooting
3
1) Stage J (Journey)
Introduction
RDBMS is one of the most widely used pluggable software components in most
enterprise software applications. Though RDBMS applications have been there since the
early 1970s, they have improved tremendously in terms of their features, the size of
data they can hold, and the complexity over the last 20 years.
MySQL is one of the very widely used commercial RDBMS systems and at this
point is the market leader as far as RDBMS is concerned. Oracle9i is RDBMS software
which supports SQL – 1999. It also supports programming language extension to SQL
called PL/SQL which is Oracle proprietary and is very popular to do program
development at the database server level. Other popular DBMS software like Sybase and
SQL Server support their own programming extensions to SQL.
2) Stage a1 (apply)
Lab Activities:
Lab instructor will demonstrate the Installation procedure of MySQL Workbench
Community Edition to students at one of the System/Laptop.
Download/Install MySQL: The main link for MySQL Community Edition for
Windows is at: http://dev.mysql.com/downloads/windows/ with the suggestion that
the MySQL Installer option at http://dev.mysql.com/downloads/windows/installer/)
be chosen.
4
There are two options on the above page for the Installer. The first, allows you to
choose the desired tools of MySQL to install, and select just Server and Workbench. Note
that the 32 bit installer in both cases for the figure above contains all of the required
steps to install either a 32 or 64 bit Windows version. Download and start the installer
and it will take you through a series of steps –the first of which is to select the “Custom”
option that allows you select MySQL Server 64 bit and MySQL Workbench 64 bit
versions for download and install. Just follow the instructions from that point on, which
includes not only the two different tools, but also configuring a development server for
MySQL that will run on your PC/laptop. Note that you want to restart after the install
has successfully completed.
5
Select File, Open SQL Script, and browse to the directory to select demo-
1.12.0.sql and from the window below, select, the Open option
6
In addition, you can open a model –using File/Open Model using openmrs.mwb
from the webpage to get:
From this model, you can click on the EER1 diagram icon to yield:
Lastly, if you have installed MySQL successfully, you can then actual import the
database that is in demo-1.12.0.sql into an actual database using Workbench. Below is a
list of steps to accomplish this:
7
i. Give the connection a name, e.g. Localhost
ii. Click OK after the IP address and credentials are properly set (the default
configuration is 127.0.0.1, username = root and no password).
8
5. On the new window, click OK to connect to the database.
i. Let the SQL script run until it finishes (this may take some time).
6. Your openmrs database is now fully imported into the schema you selected/wrote.
The screen below also shows SQL queries that have been written in the Query1 window.
You can write queries and select one and then use the lightning bolt icon to run the query.
The result of the SELECT * FROM OpenMRS.Person; query is shown in the Result Grid
window of the first table; the result of SELECT * FROM OPENMRS.person_name; is
shown in the second window.
9
3) Stage v (verify)
Activity:
Students will install MySQL Workbench on their own Laptops/Systems
4) Stage a2(assess)
Student will show installation of tool to the Lab instructor. Instructor will ask few
questions regarding installation procedures, setting administrative passwords etc.
10
LAB # 02
Statement Purpose:
This lab will give you concept of types of database architecture
Activity Outcomes:
This lab will teach you the following topics:
Instructor Note:
Discussion with students regarding different activities.
11
1) Stage J (Journey)
Introduction
DBMS architecture
In 1-tier architecture, the DBMS is the only entity where the user directly sits on the
DBMS and uses it. Any changes done here will directly be done on the DBMS itself.
It does not provide handy tools for end-users. Database designers and programmers
normally prefer to use single-tier architecture.
The architecture of DBMS is 2-tier, then it must have an application through which
the DBMS can be accessed. Programmers use 2-tier architecture where they access
the DBMS by means of an application. Here the application tier is entirely
independent of the database in terms of operation, design, and programming.
12
A 3-tier architecture separates its tiers from each other based on the complexity of the users
and how they use the data present in the database. It is the most widely used architecture to
design a DBMS.
Database (Data) Tier − At this tier, the database resides along with its query
processing languages. We also have the relations that define the data and their constraints at
this level.
Application (Middle) Tier − At this tier reside the application server and the
programs that access the database. For a user, this application tier presents an abstracted
view of the database. End-users are unaware of any existence of the database beyond the
13
application. At the other end, the database tier is not aware of any other user beyond the
application tier. Hence, the application layer sits in the middle and acts as a mediator
between the end-user and the database.
User (Presentation) Tier − End-users operate on this tier and they know nothing
about any existence of the database beyond this layer. At this layer, multiple views of the
database can be provided by the application. All views are generated by applications that
reside in the application tier.
Multiple-tier database architecture is highly modifiable, as almost all its components are
independent and can be changed independently.
2) Stage a1 (apply)
Example of 3-tier Architecture:
14
3) Stage v (verify)
Search more practical example related to 2-tier, 3-tier and n-tier architecture.
4) Stage a2(assess)
Through viva or practical demonstration
15
LAB # 03/04
Statement Purpose:
Demonstrate how to draw ERD of Real Time problem.
Activity Outcomes:
Understanding and Designing of ERDs using data modeling in Workbench
Instructor Note:
Discussion with students regarding home activities.
16
1) Stage J (Journey)
The Entity-Relationship (ER) model is a high-level conceptual data model that is widely
used in the design of a database application. The ER model represents data in terms of:
Entities
Attributes of entities
Relationships between entities
There are several case tools to automate the drawing of diagram. Most of them have a
feature of associating the diagram with specific database. This feature make easy to
further process in designing and implementing to specific database.
2) Stage a1 (apply)
Lab Activities:
Activity 1:
How to draw ER diagram in MYSQL workbench
17
Step 3: A wizard will come. Select from "Stored Connection" and press "Next" button.
Activity 2:
Conceptual ERD Symbols
These symbols are generally used for conceptual data models, although some aspects may
spill over into logical data models
ENTITIES
Entities are objects or concepts that represent important data. They are typically nouns,
e.g. customer, supervisor, location, or promotion.
Strong entities exist independently from other entity types. They always
possess one or more attributes that uniquely distinguish each occurrence of the
entity.
Weak entities depend on some other entity type. They don't possess unique
attributes (also known as a primary key) and have no meaning in the diagram
without depending on another entity. This other entity is known as the owner.
Associative entities are entities that associate the instances of one or more
entity types. They also contain attributes that are unique to the relationship
between those entity instances.
18
RELATIONSHIPS
Relationships are meaningful associations between or among entities. They are
usually verbs, e.g. assign, associate, or track. A relationship provides useful
information that could not be discerned with just the entity types.
Weak relationships, or identifying relationships, are connections that exist
between a weak entity type and its owner.
ATTRIBUTES
Attributes are characteristics of either an entity, a many-to-many relationship,
or a one-to-one relationship.
Multivalued attributes are those that are capable of taking on more than one
value.
Derived attributes are attributes whose value can be calculated from related
attribute values.
ERD Notation
Relationships illustrate an association between two tables. In the physical data
model, relationships are represented by stylized lines.
Cardinality and ordinality, respectively, refer to the maximum number of times
an instance in one entity can be associated with instances in the related entity,
and the minimum number of times an instance in one entity can be associated
19
with an instance in the related entity. Cardinality and ordinality are represented by the
styling of a line and its endpoint, as denoted by the chosen notation style.
Activity 2:
20
insurance purposes. It keeps each dependant’s: name, gender, birth date, and
relationship to employee.
Example 2:
The owners of a small computer repair shop would like to keep track of the repair jobs
for computers they repair, the items used for each repair job, the labor costs for each
repair job, the repairmen performing each repair job, and the total cost of each repair
job. When customers bring their computers in to be repaired, they make a deposit on
the repair job and are given a date to return and uplift their computer. Repairmen then
perform repairs on the customers’ computers based on the repair job, and detail the
labor costs and the items used for each repair job. When customers return they pay the
total cost of the repair job less the deposit, collect a receipt for their payment, and uplift
the repaired computer using this payment receipt.
21
3) Stage v (verify)
Activity:
The registrar at a small college wants an application that will help their department
keep track of the schedule of classes, the courses and lecturers appearing in the
schedule, and the students registering for courses according to the schedule.
Courses are scheduled every semester and this is documented in the schedule of
classes, which also documents the lecturers assigned to each schedule of a class.
Students register for courses according to the schedule of classes. Users (students,
lecturers, and other college staff) must login to the application to gain access, and
the application must keep track of user logins/logouts. In addition, users must have
different levels of access, which will determine their access to different parts of the
application.
22
4) Stage a2(assess)
Task 1: Students will select the topic of their own choice and gather information
regarding that topic.
Task 2: Identify Entity, Attribute and Relationship among them
Task 3: Draw ER diagram in MYSQL
23
LAB # 05
Statement Purpose:
This lab will give us the concept and different examples of how to map ER-diagram in to
Relational Model
Activity Outcomes:
Understanding and implementation to Map ER-Model to Relation Model
Instructor Note:
Discussion with students regarding their own case scenarios
24
1) Stage J (Journey)
ER-Diagram
2) Stage a1 (apply)
Example of Entity Set:
25
Location
(Latitude, longitude, description, last_visited)
26
Example of Relationship Set:
Account schema:
account (account_number, balance)
check schema:
o Discriminator is check_number
o Primary key for check is:
(account_number, check_number)
Check (account_number, check_number, check_date, recipient, amount,
memo)
3) Stage v (verify)
Home Activity:
Convert your ER-model into relational model
4) Stage a2(assess)
Implementation through practical and viva
27
LAB # 06
Statement Purpose:
This lab gives you the concepts of Relational Model, its constraint, Database schema, update
operation, transaction and dealing with constraint violation.
Activity Outcomes:
Understanding and practical view of following topics:
Relational Model
Attribute domain
Schema instances
Relational model constraints
Relational database schema
Operation and dealing with constraint violation
Instructor Note:
Discussion with students regarding home activities.
28
1) Stage J (Journey)
Introduction
Attribute Domain
The set of allowed values for each attribute is called the domain of the attribute
Attribute values are (normally) required to be atomic; that is, indivisible
o E.g. the value of an attribute can be a single account number, cannot be a
set of account numbers
Schema Instance
Constraints
o Restrictions on the actual values in a database state
o Derived from the rules in the mini world that the database represents
29
Four major constraints:
o Domain constrain
o Key constraints
o Entity Integrity constraints
o Referential integrity constraint
2) Stage a1 (apply)
Example of domain constraints
For example:
Example:
30
o For Example, if more than one tuple has a null value in its primary key, we may
not be able to distinguish them.
Example of Referential integrity constraint
31
3) Stage v (verify)
Home Activity:
Apply different types of domain constraints, relational model constraints on your
relational model project.
4) Stage a2(assess)
32
33