0% found this document useful (0 votes)
127 views

DBMS Lab Manual Lab 1 To 7

Here are the key points about database architectures: - 1-tier architecture: The database, application logic, and user interface are all on the same system. This is the simplest but not scalable. - 2-tier architecture: The presentation layer (user interface) is separated from the data layer (database). The application logic resides on the application server. This separates the user interface from the database but is still not very scalable. - 3-tier architecture: This separates the presentation tier, application tier, and data tier onto separate servers. The user interface resides on the client system, application logic and data access code reside on the application server, and the database resides on the database server. This is the most common
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

DBMS Lab Manual Lab 1 To 7

Here are the key points about database architectures: - 1-tier architecture: The database, application logic, and user interface are all on the same system. This is the simplest but not scalable. - 2-tier architecture: The presentation layer (user interface) is separated from the data layer (database). The application logic resides on the application server. This separates the user interface from the database but is still not very scalable. - 3-tier architecture: This separates the presentation tier, application tier, and data tier onto separate servers. The user interface resides on the client system, application logic and data access code reside on the application server, and the database resides on the database server. This is the most common
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

SHAHEED ZULFIKAR ALI BHUTTO INSTITUTE

OF
SCIENCE AND TECHNOLOGY
(SZABIST)

Course: CSCL-2203 Database Systems


Department of Computer Science

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 #

Lab # 01 - Introduction to MySQL 3


- Installation and configuration
Lab # 02 - View of 2-tier architecture 10
- View of 3-tier architecture
Lab # 03 - Create ER model using MySQL Data Modeling 15
- Show relationship diagram
Lab # 04 - Various Example of ER-Diagram with case study 15
Lab # 05 - Map ER model into relational Model 23
Lab# 06 - Practical view of relation, database schema 27
- Different operations, transition, constraints on data
Lab # 07 - Create table 32
- Insert , update and delete data
- Basic retrieval queries using Select, from and where clause
- Delete table and columns
- Alter table (adding single and multiple columns, modify
columns)
Lab # 08 - Creation of table with attribute constraints (Unique, NOT 38
Null, NULL, DEFAULT, CHECK, CREATE DOMAIN)
- Key and referential integrity (Foreign key) constraints
- Constraints on tuple using CHECK
Lab # 09 - Retrieving specific columns 44
- Printing with user define column name
- Select distinct rows, Top rows
- Using Like, IN, Between And operators
- Logical operators (And, OR, Not)
- Arithmetic operators
- Ordering record
Lab # 10 - Generating sub queries 50
- Exists and Unique functions
- Aggregate functions
- Group by and having clause
Lab # 11 - Use of JOIN in SQL 57
o Equijoin
o Natural join
o Left and right outer join
- Create, replace, drop views
Lab # 12 - Introduction to front end tool 62
- Understanding GUI
- Menu design
Lab # 13 - Connecting to database 72
- Adding recording using hard coded SQL
Lab # 14 - Add, delete, and update a new record using forms 78
- Record navigation using Forms
- Reports and filters
Lab # 15 - Project Demo

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.

Utilizing MySQL Workbench: This section provides the instructions to use


MySQL Workbench to open and create a database schema and tuples for a 5000 sized
patient database from the OpenMRS electronic medical record. To download the patient
data set, at: https://wiki.openmrs.org/display/RES/Demo+Data select the demo-
1.12.0.zip. After download, unzip to create demo-1.12.0.sql which is an SEQUEL (sql)
data file format that contains both the database schema definition as well as the actually
instances; note the is a 100 megabyte file. There is a second data set that is larger that
can also be downloaded large-demo-data-1.9.7sql.zip that generates large-demo-data-
1.9.7.sql.

Once you have downloaded and extracted to demo-1.12.0.sql, open MySQL


Workbench as below:

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

The end result will be the screen:

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:

1. Open MySQL Workbench


2. On the MySQL Connections (top-left), click the + button to add a new connection.

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).

3. Click on the newly created MySQL connection.


4. Go to File -> Run SQL Script

i. Select the demo-1.12.0.sql file from wherever it is stored in your


computer.
ii. In the default schema name, you can select a previously created schema
or write a new name so that it is created on the fly. E.g. type openmrs if
you want the script to be executed in a new database called openmrs.
iii. Default character set can be left blank. – this is a big file so may take a few
minutes
iv. Click Run on right window.

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:

- View of 1-tier architecture


- View of 2-tier architecture
- View of 3-tier architecture
- View of N-tier architecture

Instructor Note:
Discussion with students regarding different activities.

11
1) Stage J (Journey)
Introduction
DBMS architecture

The design of a DBMS depends on its architecture. It can be centralized or


decentralized or hierarchical. The architecture of a DBMS can be seen as either single
tier or multi-tier. N-tier architecture divides the whole system into related but
independent n modules, which can be independently modified, altered, changed, or
replaced.

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

Step 1: Go to "Database" Menu option

Step 2: Select the "Reverse Engineer" option.

17
Step 3: A wizard will come. Select from "Stored Connection" and press "Next" button.

Step 4: Click Next to Open EER View.

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:

ER Diagram Icons of MySQL


Key: (Part of) Primary Key
Filled Diamond: NOT NULL
Not filled Diamond: NULL
Red colored: (Part of) Foreign key
Blue lined Diamond: Simple attribute (no key)

Can be combined for example:


is a Red colored Key so it's a Primary Key which is also a Foreign Key
is a Yellow (non Red) Key so it's only a Primary Key
is a blue lined filled diamond so it's a NOT NULL simple attribute
is a red colored filled diamond so it's a NOT NULL Foreign Key
is a blue lined not filled diamond so it's a simple attribute which can be
NULL
is a red colored not filled diamond so it's a Foreign Key which can be
NULL

Different Examples of ER Diagram with Case Scenario’s


Example 1:
The Company assigns an employee to one department but may work on several
projects, which are not necessarily controlled by the same department. It keeps track of
the number of hours per week that an employee works on each project. It records the
direct supervisor of each employee. It stores the dependants of each employee for

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

 Need to convert E-R model diagrams to an implementation schema


 Easy to map E-R diagrams to relational model, and then to SQL
o Significant overlap between E-R model and relational model
o Biggest difference is E-R composite/multi-valued attributes, vs. relational
model atomic attributes
 Three components of conversion process:
o Specify schema of relation itself
o Specify primary key on the relation
o Specify any foreign key references to other relations

2) Stage a1 (apply)
Example of Entity Set:

 Geocache location E-R diagram

o Entity-set named location


 Convert to relation schema:

25
Location
(Latitude, longitude, description, last_visited)

Example of Relationship Set:

Relation schema for borrower:


 Primary key of customer is cust_id
 Primary key of loan is loan_id
 Descriptive attribute access_date
 Borrower mapping cardinality is many-to-many
borrower (cust_id, loan_id, access_date)

Example of Relationship Set:

Convert customer and loan entity-sets:


customer(cust_id, name, street_address, city)
loan(loan_id, amount)

Relation schema for borrower:


 Primary key of customer is cust_id
 Primary key of loan is loan_id
 Descriptive attribute access_date
 borrower mapping cardinality is many-to-many
borrower (cust_id, loan_id, access_date)

26
Example of Relationship Set:

Relation schema for employee entity-set:


Employee (employee_id, name)

Relation schema for works_for:


 One-to-many mapping from manager to worker
 “Many” side is used for primary key
works_for (employee_id, manager_id)

Example of Weak Entity 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

 database consists of several tables (relations)


 columns in each table are named by attributes
 each attribute has an associated domain (set of allowed values)
 data in each table consists of a set of rows (tuples) providing values for the
attributes

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

 According to schema we can have a relation (instance of this scheme), like:

STD={(stId:S001, stName:Ali, stAdres: Lahore, doB:12/12/76),

(stId:S002, stName:A. Rehman, stAdres: RWP, doB:2/12/77)}

Relational model constraints

 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:

Rooms in hotel (1-300)


Age (1-99)
Married (yes or no)
Nationality (Nepalese, Indian, American, or British)
Colors (Red, Yellow, Green)

Example:

Example of key constraints


 The concept of key and all different types of keys are applicable to the
Relations
o No two tuples can have the same combination of values for all their
attributes.
o Every tuple should be uniquely identified by key

Example of Entity-integrity constraints


 A primary key must not contain a null value.
o Else it may not be possible to identify some tuples.

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

 Specified between two relations


 Maintains consistency among tuples in two relations
 Achieved by Foreign Key

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

You might also like