LAB1 Manual

You might also like

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

a

Table of Contents
Version History..................................................................................................................................................g
Title..........................................................................................................................................................g
Created By...............................................................................................................................................g
Date of Creation......................................................................................................................................g
Maintained By.........................................................................................................................................g
Version No...............................................................................................................................................g
Changes Made.........................................................................................................................................g
Updated By..............................................................................................................................................g
Updating..................................................................................................................................................g
Date.........................................................................................................................................................g
Status.......................................................................................................................................................g
Lab Rubrics........................................................................................................................................................h
Foreword.............................................................................................................................................................j
Database Lab Objective............................................................................................................................j
Course Outcomes.....................................................................................................................................j
Pre-Lab:....................................................................................................................................................j
In-Lab:.......................................................................................................................................................j
Post Lab:...................................................................................................................................................j
Lab Policy..........................................................................................................................................................k
Lab Reports..............................................................................................................................................k
Report Format.........................................................................................................................................k
A title page..............................................................................................................................................k
Practical 1: Basic database concepts & database approach vs file-based system..............................................1
Objective.................................................................................................................................................1
Learning Outcomes.................................................................................................................................1
Activity Time Boxing................................................................................................................................1
Tools and Reading Resources..................................................................................................................1
Theoretical Explanation...........................................................................................................................2
Microsoft Access.....................................................................................................................................2
Required Steps to create and mange DB:................................................................................................2
In Lab Tasks.............................................................................................................................................4
Post Lab Tasks.........................................................................................................................................5
Task 1......................................................................................................................................................5

Department of Computer Science


Database Systems Lab Manual
b

Practical 2: Basic database concepts & database approach vs file-based system..............................................7


Objective.................................................................................................................................................7
Introduction............................................................................................................................................7
Basic concepts of DBMS..........................................................................................................................7
Why to Learn DBMS?...............................................................................................................................7
In Lab Tasks.............................................................................................................................................9
Task 1......................................................................................................................................................9
Post Lab Tasks.........................................................................................................................................9
Task 1......................................................................................................................................................9
Practical 3: Introduction to Structured Query Language (SQL)......................................................................10
Objective...............................................................................................................................................10
Introduction..........................................................................................................................................10
SQL........................................................................................................................................................10
Rules:.....................................................................................................................................................10
SQL process:..........................................................................................................................................10
In Lab Tasks...........................................................................................................................................11
Task 1....................................................................................................................................................11
Task 2....................................................................................................................................................11
Post Lab Tasks.......................................................................................................................................12
Task 1....................................................................................................................................................12
Practical 4: Relational Data Model..................................................................................................................13
Objective...............................................................................................................................................13
Introduction..........................................................................................................................................13
What is a Relational Model?..................................................................................................................13
In Lab Tasks...........................................................................................................................................14
Task 1....................................................................................................................................................14
Post Lab Task.........................................................................................................................................14
Task 1....................................................................................................................................................14
Practical 5: Entity relationship model and entity-relationship diagrams........................................................15
Objective...............................................................................................................................................15
Introduction..........................................................................................................................................15
What is an ER Diagram?........................................................................................................................15
ER Diagrams Symbols & Notations........................................................................................................15
ER Diagram Symbols..............................................................................................................................16
In Lab Tasks...........................................................................................................................................16

Department of Computer Science


Database Systems Lab Manual
c

Task 1....................................................................................................................................................16
Post Lab Tasks.......................................................................................................................................16
Task 1....................................................................................................................................................16
Practical 6: Relational algebra.........................................................................................................................17
Objective...............................................................................................................................................17
Introduction..........................................................................................................................................17
Relational Algebra.................................................................................................................................17
Basic SQL Relational Algebra Operations...............................................................................................17
SELECT (σ)..............................................................................................................................................17
Output -.................................................................................................................................................18
rejection(π)............................................................................................................................................18
Union operation (υ)...............................................................................................................................18
Example.................................................................................................................................................19
Set Difference (-)...................................................................................................................................19
Example.................................................................................................................................................20
Example:................................................................................................................................................21
In Lab Tasks...........................................................................................................................................21
Task 1....................................................................................................................................................21
Post Lab Tasks.......................................................................................................................................21
Task 1....................................................................................................................................................21
Practical 7: Joins and sub queries in SQL.......................................................................................................22
Objective...............................................................................................................................................22
Introduction..........................................................................................................................................22
Joins.......................................................................................................................................................22
Sub query..............................................................................................................................................22
Advantages of Joins...............................................................................................................................22
Advantages of Sub query.......................................................................................................................22
SQL left join keyword.............................................................................................................................23
SQL right join keyword..........................................................................................................................23
In Lab Tasks...........................................................................................................................................23
Tasks 1...................................................................................................................................................23
Post Lab Tasks.......................................................................................................................................24
Tasks 1...................................................................................................................................................24
Practical 8: Grouping and aggregation in SQL................................................................................................25
Objective...............................................................................................................................................25

Department of Computer Science


Database Systems Lab Manual
d

Introduction..........................................................................................................................................25
SQL GROUPING......................................................................................................................................25
Important Points...................................................................................................................................25
Syntax....................................................................................................................................................25
SQL Aggregation....................................................................................................................................25
In Lab Tasks...........................................................................................................................................25
Task 1....................................................................................................................................................25
Post Lab Tasks.......................................................................................................................................25
Task 1....................................................................................................................................................25
Practical 9: Functional dependencies...............................................................................................................26
Objective...............................................................................................................................................26
Introduction Functional Dependency....................................................................................................26
Example:................................................................................................................................................26
Rules of Functional Dependencies.........................................................................................................26
Types of Functional Dependencies in DBMS.........................................................................................26
Dependencies in DBMS.........................................................................................................................26
Multivalued Dependency in DBMS........................................................................................................27
Example:................................................................................................................................................27
Trivial Functional Dependency in DBMS................................................................................................27
Example.................................................................................................................................................27
Example.................................................................................................................................................28
Transitive Dependency in DBM.............................................................................................................28
Example.................................................................................................................................................28
Advantages of Functional Dependency.................................................................................................29
In Lab Tasks...........................................................................................................................................29
Task 1....................................................................................................................................................29
Post Lab Tasks.......................................................................................................................................29
Task 1....................................................................................................................................................29
Practical 10: Normalization.............................................................................................................................30
Objective...............................................................................................................................................30
Introduction..........................................................................................................................................30
Students................................................................................................................................................31
Faculty...................................................................................................................................................31
In Lab Tasks...........................................................................................................................................32
Task 1....................................................................................................................................................32
Department of Computer Science
Database Systems Lab Manual
e

Post Lab Tasks.......................................................................................................................................32


Task 1....................................................................................................................................................32
Practical 11: Concurrency control...................................................................................................................33
Objective...............................................................................................................................................33
Introduction..........................................................................................................................................33
Potential problems of Concurrency.......................................................................................................33
o Lost Updates..................................................................................................................................33
o Non-Repeatable Read....................................................................................................................33
o Incorrect Summary issue...............................................................................................................33
Concurrency Control Protocols..............................................................................................................34
In Lab Tasks...........................................................................................................................................34
Task 1....................................................................................................................................................34
Post Lab Tasks.......................................................................................................................................34
Task 1....................................................................................................................................................34
Practical 12: Database backup and recovery...................................................................................................35
Objective...............................................................................................................................................35
Introduction..........................................................................................................................................35
SQL Server Backup.................................................................................................................................35
Reasons of Failure in a Database...........................................................................................................35
Methods of Backup...............................................................................................................................35
o Full Backup....................................................................................................................................35
o Transaction Log.............................................................................................................................36
o Differential Backup........................................................................................................................36
Database Recovery................................................................................................................................36
In Lab Tasks...........................................................................................................................................36
Task 1....................................................................................................................................................36
Post Lab Tasks.......................................................................................................................................36
Task 1....................................................................................................................................................36
Practical 13: Indexes........................................................................................................................................37
Objective...............................................................................................................................................37
Introduction..........................................................................................................................................37
What is Indexing?..................................................................................................................................37
Types of Indexing..................................................................................................................................37
Type of Indexes in Database..................................................................................................................38
In Lab Tasks...........................................................................................................................................38
Department of Computer Science
Database Systems Lab Manual
f

Task 1....................................................................................................................................................38
Post Lab Tasks.......................................................................................................................................38
Task 1....................................................................................................................................................38
Practical 14: Advanced Data Modelling (OEL-3)...........................................................................................39
Objective...............................................................................................................................................39
Introduction..........................................................................................................................................39
In Lab Tasks...........................................................................................................................................39
Task 1....................................................................................................................................................39
Practical 15: Advanced SQL...........................................................................................................................40
Objective...............................................................................................................................................40
Introduction..........................................................................................................................................40
SQL Server Views...................................................................................................................................40
SQL Server Indexes................................................................................................................................40
SQL Server Stored Procedures...............................................................................................................40
SQL Server User-defined Functions.......................................................................................................40
SQL Server Triggers................................................................................................................................40
Practical 16: NoSQL Systems.........................................................................................................................42
Objective...............................................................................................................................................42
Introduction..........................................................................................................................................42
What is NoSQL?.....................................................................................................................................42
In Lab Task.............................................................................................................................................43
Post Lab Task.........................................................................................................................................43

Department of Computer Science


Database Systems Lab Manual
g

Version History

Title Database Lab Manual

Created By Lecturer Saima Yasmeen

Date of Feburary 2023


Creation
Maintained By

Updating
Version No. Changes Made Updated By Status
Date

v-1.0 Rubrics Lecturer Saima Yasmeen 16-03-2021 ---

Provision of
Practicals Lecturer Saima Yasmeen
15-04-2021 ---
v-1.1 Practicals’ Lab Engineer Tabinda NAsir
Additions

Practicals’ Review Lecturer Saima Yasmeen 25-04-2021 ---


v-1.2

Restructuring Lecturer Saima Yasmeen 30-09-2021 Active


v-1.3

Department of Computer Science


Database Systems Lab Manual
h

Lab Rubrics
All lab reports shall be marked on following Rubrics, the indicated percentage will be out of the report’s marks, for example, if a report is of 10
marks, then specifications shall carry 3.2, originality shall carry 2.8 and object-oriented design shall carry 4 marks.
I. The program is The program The program works The program The program is well-tested for
Specifications producing produces correct and produces the works and meets all valid and in-valid test
32% incorrect results results but does not correct all of the scenarios
display them Results and displays specifications.
correctly. them correctly. It
also meets most of
the other
specifications.

II. The code logic is Code logic is Code logic is self- Code logic is Code logic is completely
Code completely partially copied written with few completely self- self-written and meets all
Originality 28% forged/outputs are and reference of flow written with few requirements
created instead of source is discrepancies errors
produced demonstrated

III. The student is unable to The student The student The student The student adequately
Database demonstrate any database demonstrates adequately adequately demonstrates the concepts of
Design 40% concepts or knowledge. partial knowledge demonstrates the demonstrates the database design, relational
and concepts of concepts of concepts of data model, SQL, joins,
database design. database design, database design, And/or normalization.
relational data relational data Applies advanced knowledge
model, SQL, model, SQL, of database management
joins, and/or joins, and/or including concurrency tools,
normalization. normalization. backup, and/or recovery. The
Department of Computer Science Database Systems Lab Manual
i

Applies database used is well designed


advanced and has met all criteria of
knowledge of excellent design and
database architecture and
management normalization.
including
concurrency
tools,
Backup, and/or
recovery. The
database used is

Department of Computer Science Database Systems Lab Manual


j

Foreword
Database Lab Objective
The major objective of this lab is to provide a strong foundation about database concepts,
technology used for databases and help students to develop the skill of using and creating well-
informed database applications. It enables them to gain knowledge in lab applications of databases.
This lab will help them to familiarize the participant with the nuances of database environments
towards an information-oriented data-processing oriented framework, to give a good formal
foundation on the relational model of data, to present SQL and procedural interfaces to SQL
comprehensively
Course Outcomes
At the end of this lab session, the student will be able to solve real world problems using database
concepts and technology. They will have lab knowledge on the applications of databases.
The lab manual is organized in such a way that the students can directly use it in the laboratory.
Each laboratory exercise comprises of
1. Statement of the problem

2. Solution

3. Results

4. Conclusion

Students must follow this sequence to conduct any database experiment in the lab and write
your report accordingly. The lab is divided into 3 stages. Each stage exemplifies various
concepts. At each stage there are database examples that can be an example of how your
database should look like.

Pre-Lab: At this stage student will come with a proposed solution of the
problem given. When the Lab starts after lab demonstration the problem task
of each individual student will be assessed

In-Lab: At this stage student will go through multiple scenarios and practice their subject
knowledge in it. Group practice is integrated at this stage where student in group of two
perform lab tasks on respective software/tools.

Post Lab: After Lab is completed at this level student will perform given problems at home to
further strengthen their concepts and impart their creative skills.

Department of Computer Science


Database Systems Lab Manual
k

Lab Policy

Students will be formed into groups / syndicates of two or three on the first lab
day. This pair programming approach may vary depending upon the
experiment nature. However, once a student has signed up with a group in term
project, he may not change groups without prior approval of the instructor.
Lab Reports
Students will perform the Experiment/Lab in group (optional), and turn in
individual laboratory reports on the assigned date of deadline mentioned at the
beginning of each lab experiment detailed document. Your report should be
self-contained, i.e. a computer scientist should be able to perform the
experiment and duplicate your results by reading your report. DO NOT
"adjust" your data to make them fit what you believe to be an acceptable value.
Plagiarism is strictly forbidden in individual reports. Those Students who
found in such activities will be awarded no credits plus re-submission will not
be entertained. For each Lab Task maintain screenshots of results along with
all the program files as a record in a separate lab folder with name of student id
or group id. Task Screenshots should be shown along with program source
code as evidence of task implementation. In order to achieve the expected
results do not “adjust” your actual results instead explain the discrepancies.
Report Format
A report should include the following order.
A title page, which includes the following information, in given format:

Department of Computer Science


Database Systems Lab Manual
l

Data base Systems Lab


Lab Code: CS4012

Subject/Course Name
Database Systems Lab
Depar
Registration Number/Name Semester/Section
tment
Comp
uter
Scien
ce
Instructor’s
Date Instructor’s Name
Signature

B. Objective or purpose and scope of the experiment work.


C. Theoretical aspect of the experiment.
D. Experimental procedure that explains briefly the pseudo code or algorithm used to carry
out the experiment by utilizing the equipment and data provided.
E. Experimental and /or calculated results. (Include all data (screenshots, numeric) you have
taken, a sample calculation, and the results). All results should be documented as well as
maintained in electronic form. Hand written results or source code will not be accepted
F. Discussion of results in light of the theoretical “predictions”. Include an
error analysis. Quantify the errors whenever possible.
G.Conclusions, wherein you write what you learned from the experiment.
Your conclusions must summarize your report and must be based on your
experimental results.

Department of Computer Science


Database Systems Lab Manual
13

Practical 1: Basic database concepts & database


approach vs file-based system
Objective

Data is a collection of raw facts and figures processed to obtain useful information to assist
an organization in making decisions. Database is an organized collection of related data. In
order to manage the databases, DBMS offers sets of program and tools

Learning Outcomes
After performing this lab student should be able to
o Install required software
o Explore MS Access Interface
o Explore MS Access Fundamental Objects Like Tables, Forms, Query
o Explore Object Table and its views in MS Access
o Explore Different datatypes in MS Access

Activity Time Boxing

1 Concept Deliverance 30
Exploring MS Access Interface
Creating table and Entering data
2 10
Exploring and applying various
datatypes
3 Evaluation/Marking 60
Total Time: 100

Tools and Reading Resources


 Book: Object Oriented Programming in C++ by Robert Lafore, Chap 2
 MS Access (Latest Edition)

Department Of Computer Science Database Systems Lab Manual


14

Theoretical Explanation

Microsoft Access
Microsoft Access is a database management tool that is part of the Microsoft Office suite. It's
designed to help users store, organize, manage, and retrieve information easily. Here’s a
simple breakdown of what it does:
 Database Creation: You can create a database from scratch or use templates. A
database is like a digital filing cabinet where you store data in an organized manner.
 Tables for Data Storage: Inside the database, you use tables to store your data. Think
of tables like sheets in a spreadsheet, each with rows and columns. Each row
represents a record, and each column represents a field (a specific piece of data like a
name or a date).

Required Steps to create and mange DB:

Creating a new database in Microsoft Access is a straightforward process. Here are the steps
to create a new database from scratch:
1. Open Microsoft Access: Start by opening Microsoft Access. If you're using
Windows, you can find it by searching for "Access" in the start menu.
2. Choose to Create a New Database:
 On the Access startup screen, you'll see options to open an existing database
or to create a new one. Click on "Blank database" to start a new project from
scratch.

3. Name Your Database:


 After clicking on "Blank database," you will be prompted to give your new
database a name. In the "File Name" field, enter a descriptive name for your

Department Of Computer Science Database Systems Lab Manual


15

database.

 Choose where you want to save your database on your computer by clicking
the folder icon next to the file name field to browse your computer's
directories. Select a location and then click "Create."
4. Access Interface:
 Once you've created your database, Access will open to a new, blank table in
Datasheet View. This is where you can start entering data directly.

5. Switch to Design View (Optional but Recommended for Setup):


 To set up your table with specific data types and properties, it’s better to
switch to Design View before entering data. Click on "View" in the Ribbon
(the toolbar at the top), then select "Design View."

Department Of Computer Science Database Systems Lab Manual


16

 In Design View, you can define the structure of your table: name your
fields (columns), specify the type of data each field will hold (e.g., Text,
Number, Date/Time), and set a primary key (a unique identifier for each
record in your table).
 The data type determines the kind of the values that users can store in
any given field.
 Each field can store data consisting of only a single data type.

6. Save Your Table:


 After setting up your fields, save your table by clicking the save icon or
pressing Ctrl+S. You will be prompted to give your table a name. Enter a
descriptive name and click "OK."
7. Enter Data:
 Once your table is set up, switch back to Datasheet View to start entering your
data. You can add new records directly into the table by typing into the rows
under each field.

In Lab Tasks

Task 1: Explore the Microsoft Access Interface


 Objective: Become familiar with the Microsoft Access environment and its key
components.
 Instructions:
1. Open Microsoft Access and create a new blank database.
2. Locate and describe the purpose of the following tools in the Ribbon: Table
Design, Query Design, Form Design, and Report Design.

Task 2: Create a Table and Enter Data


 Objective: Learn how to create a table, understand table views, and practice entering
data.
 Instructions:
1. Create a new table in Datasheet view. Save the table as “Students” when
prompted.
2. Add the following fields to the table by typing them directly into the datasheet
column headings: StudentID, FirstName, LastName, and EnrollmentDate.
3. Switch to Design View (right-click the table tab and select Design View).
Observe how Access prompts you to save changes.
4. In Design View, specify StudentID as the primary key by selecting the field
and clicking the Primary Key button in the Ribbon.
5. Return to Datasheet view and enter data for at least 7 students reecord.

Task 3: Introduction to Data Types


 Objective: Understand different data types in Microsoft Access and how to apply
them.
 Instructions:
1. In the “Students” table Design View, examine the Data Type column for each
field you created.
2. Change the Data Type of the EnrollmentDate field to “Date/Time” if it is not
already set.

Department Of Computer Science Database Systems Lab Manual


17

3. Add a new field named EmailAddress. Set its Data Type to “Short Text” and
specify a field size of 255 characters.
4. Add another field named CreditsEarned. Set its Data Type to “Number” and
under Field Size, select “Integer”.
5. For each field, describe in a brief document why the chosen data type is
appropriate for the content it will hold.

Post Lab Tasks

Task 1

Post-Lab Task 1: Design and Populate a Personal Library Database


 Objective: Apply the concepts learned in the lab to create a database for managing a
personal library, focusing on table creation, data entry, and data types application.
 Instructions:
1. Database Creation: Create a new Microsoft Access database named
“PersonalLibrary.accdb”.
2. Table Design: Create a table named “Books” with the following fields:
 BookID (Primary Key, AutoNumber)
 Title (Short Text)
 Author (Short Text)
 PublishedYear (Number, Integer)
 Genre (Short Text)
 ISBN (Short Text)
 Available (Yes/No) – to indicate whether the book is available for
borrowing.
3. Data Types Application: Carefully select and apply the most appropriate data
type for each field, considering the nature of the data that will be stored.
4. Enter Sample Data: Populate the table with data for at least 10 books. This
can include books you own, books you'd like to read, or classic literature.
5. Documentation: Write a brief summary (1 page) reflecting on the process.
Include in your summary:
 The rationale behind your data type choices for each field.
 Any challenges you encountered while designing the table or entering
data and how you resolved them.

Department Of Computer Science Database Systems Lab Manual


18

 How this task helped solidify your understanding of Microsoft Access


functionalities.
 Submission Guidelines:
 Submit the “PersonalLibrary.accdb” file.
 Include your summary document as a PDF or Word file.

Department Of Computer Science Database Systems Lab Manual

You might also like