Section 1 Dbms Lab: Structure Page No
Section 1 Dbms Lab: Structure Page No
Section 1 Dbms Lab: Structure Page No
1.0 INTRODUCTION
By now, you must have obtained the practical skills of several programming
languages. However, when we want to create a secure, managed database application,
we need not re-start from scratch and develop a huge system using a programming
language; rather we use a database management system: application software. This
software allows us to create database, query, report and many more operations with
database. This section attempts to provide you the basic skills of data organisation,
including database creation, integrity enforcement, query formulation, forms and
report creation, etc. You should write SQL queries as well as work using interface
provided in software packages. For the present practical we have selected
MS-Access. However, you must try to develop some applications using MySQL.
You must go through the MCS-023 courseware in order to get the best of those
sessions. During the practical sessions you can make suitable assumptions if
necessary.
1.1 OBJECTIVES
By the end of the practical sessions of this section, you will be able to:
After opening Access as indicated in Figure 1 above, you will be presented with the
Window shown in Figure 2. You can select one of the first two options if you are
creating a new database, then go to the second option. If you want to edit an existing
database, then go to the third option as shown in Figure 2.
If the database was opened recently on the computer, it will be listed on the main
window (as shown in Figure 2). Highlight the database name and click OK.
You can select the folder where your database should reside and type the name of the
database in the File name and click the Create button.
Database Components
The Database Window as shown below in Figure 4 organizes all of main objects in
the database like tables, queries, form and reports. Further in this we will discuss all
these important components of database, which you will need in your lab exercises.
7
Lab Manual
Introduction to Tables
A Microsoft Access database is a collection of database files, which are also known as
Tables. And each database ( a table) is a collection of records, and a record is a
collection of fields. You can also understand that the tables are a collection of cells
that store information similar to the way an MS-Excel (If you don’t know about Excel
you can go and check it) worksheet does. MS-Access provides three ways to create a
table.
1. Create table in Design view will allow you to create the fields of the table.
(Design view is the best way for you).
2. Create table using wizard. (This is best when you are beginning to learn).
3. Create table by entering data, will give you a blank datasheet with unlabelled
columns that looks much like an Excel worksheet.
Let us introduce you to Soft Garments, wholesalers for shirts, trousers, and T-shirts.
They purchase from various manufacturers and wholesalers. The company has four
departments – Sales, Accounts, Stores and Payroll. There are around 2000 employees
working under the organization. The company wants to maintain a database, which
will store the details and the entire information about all the employees. They want to
store the Employee Code, Employee Name, Date of Birth, Date of Joining,
Designation, Department and Photographs of the Employees.
Now, if the Soft Garments wants to store the employee details, they will have to make
a table, which will be a part of some database. The information about one employee
will make one record of that table, and the information will be stored under fields as
shown in Figure 5, fields are EmployeeID and FirstName and others.
Each record in a table contains the same set of fields and each field contains the same
type of information for each record.
Introduction to Queries
Queries select records from one or more tables in a database so they can be viewed,
analyzed, and sorted on a common datasheet. The resulting collection of records,
called a dynaset (short for dynamic subset), is saved as a database object and can
8
DBMS Lab
therefore be easily used in the future. The query will be updated whenever the original
tables are updated. Types of queries are select queries that extract data from tables
based on specified values, find duplicate queries that display records with duplicate
values for one or more of the specified fields, and find unmatched queries display
records from one table that do not have corresponding values in a second table.
Assume that you are a senior executive in the Soft Garments and heading the payroll
department. One day the manager of the company calls you, and wants to know how
many employees are in ‘A’ grade. Will you be in a position to answer that Query,
right at that moment? May be Yes, May be No. Keeping track of 2000 employees is
quite difficult. Not to worry. The manager had a query, he asked you. If you don’t
know the answer, since you kept your data in database, you can ask the ‘Query’ to
your database.
In MS-Access, A Query is a question you ask about the data in your database. The
data that answers the question can be from a single table or several – the query brings
the information together.
For solving the above query asked by the manager you can write the following query
in access SQL view. As shown in Figure 7 after performing this query on the
Employee table you will get the result showing details about employees are who in
Grade A. In this example, you have very few employees listed but it is really helpful
when the number of employees is huge like 2000 or 20000.
9
Lab Manual
10
DBMS Lab
Afterwards select the layout and visual style for the form from the next set of options
and click Next. On the final screen, name the form in the space provided. Select
“Open the form to view or enter information” to open the form in Form View or
“Modify the form’s design” to open it in Design View. Click Finish to create the form.
As shown in Figure 11 you can add controls to the form by clicking and dragging the
field names from the Field List floating window. Access creates a text box for the
value and label for the field name when this action is accomplished. To add controls
for all of the fields in the Field List, double-click the Field List window’s title bar and
drag all of the highlighted fields to the form.
11
Lab Manual
Reports
Forms and Queries present the data on screen. Reports are used to present data on
printed-paper. It provides a way to retrieve and present data as meaningful
information, which might include totals and grand totals, which have to be shown
across an entire set of records. Similar to Form in Reports creation also Access
provides two ways for report creation. As shown in Figure 12 you can select any way
of report creation. For example in Figure 13 you can see a report showing summary
report of employee sales and category sale.
12
DBMS Lab
Session 1: In this session you need to create database for an Employee management
system of an ABC organisation. The details about different tables are given below.
According to that you can proceed further and create tables using MS-Access.
Employee
First name - Not NULL
Middle initials -
Last name - Not NULL
Employee-id - Primary Key
Date of Birth -
Address -
Gender - M or F
Salary - Range of 5000 to 25000
Date of Joining -
Department number - Refers to Department Number of
Department table.
Department
Department name - Not NULL unique
Department number - Primary Key
Manager_id - Refers to employee-id of employee
table.
Manager date of joining - Not NULL.
Department location
Department number - Refers to Department number of
department table.
Department location - Not NULL.
Department number & Department location are combined Primary Key.
Project
Project name - Not NULL.
13
Lab Manual
Project number - Primary Key.
Project location - Not NULL.
Department number - Refers to department number of
Department table.
Works-on
Employee-id - Not NULL refers to employee-id of
employee table.
Project number - Not NULL refers to Project number
of Project table.
Hours - Not NULL.
Employee-id & Project number are combined primary key.
Dependent
Employee-id - Refer to employee table employee id
field
Dependent name -
Gender - M or F
Date of Birth - Not NULL
Relationship - Not NULL
Now enter a few sets of meaningful data and answer the following queries.
1. List the department wise details of all the employees.
2. Find out all those departments that are located in more than one location.
3. Find the list of projects.
4. Find out the list of employees working on a project.
5. List the dependents of the employee whose employee id is ‘001’
Session 2:
This session is similar to the previous one, but in this session assume that you are
developing a prototype database of the IGNOU library management system, for that
you need to create the following tables:
(a) Book Records
(b) Book details
(c) Member details and
(d) Book issue details
Members Member Id
Member Name
Maximum Number of books that can be issued
Maximum Number of days for which book can be issued
14
DBMS Lab
Issue Date
Return Date
1. Get the list of ISBN-Number, Book name, available copies of the books of
which available copies are greater than zero.
2. Get the list of ISBN-Number, Book name, Total copies, available copies of the
book of which available copies are greater than zero. List should be displayed in
alphabetical order of book name.
3. Get the list of ISBN number, Book name, Author, total copies, cost (cost is
price ´ total copies). List should be displayed in descending order of cost.
4. Get the list of books issued to each member.
5. Write query to know the maximum and average price of the books.
6. Get the list of all existing members and the number of days for which a member
is allowed to keep the book. Also find out the members who have got the
maximum number of books issued.
7. Get the list of member codes of those members who have more than two books
issued.
15
Lab Manual
8. Find the details of the books presently issued to a member.
9. Create the history of issue of a book having a typical accession number.
10. To set the width of the book name as 35.
Session 4:
Create the following table and perform the necessary tasks defined below one by one.
You must use the query tools/ SQL/ Reports/ Forms/ Graphs/Views/ using
client/server wherever needed.
a. Update Phone numbers of all customers to have a prefix as your city STD Code
b. Print the entire customer table
c. List the names of those customers who have ‘e’ as second letter in their names.
d. Find out the Customer belonging to area ‘abc’
e. Delete record where area is NULL.
f. Display all records in increasing order of name.
g. Create a table temp from customer having customer-id, name, and area fields
only
h. Display area and number of records within each area (use GROUP by clause)
i. Display all those records from customer table where name starts with ‘a’ or area
is “abc.”
j. Display all records of those where name starts with ‘a’ and phone exchange is
55.
2. Answer the following queries using Library system as created earlier. You must
create a view to know member name and name of the book issued to them, use
any inbuilt function and operators like IN, ANY, ALL, EXISTS
a. List the records of members who have not been issued any book using EXISTS
operator.
b. List the members who have got issued at least one book (use IN / ANY
operator).
c. List the books which have maximum Price using ALL operator.
d. Display Book Name, Member Name, Issue date of Book. Create a view of this
query of the currently issued books.
a. Display all records from employee table where department is not found in
department table.
b. Display records from employee table in a report format with proper headings.
This report must also contain those records where department number does not
match with any value of department table.
16
DBMS Lab
c. Display those employee records who have salary less than the salary of person
whose empcode= ‘A100’.
d. Create another table : Sales_data (Region-code, City, Salesperson-code, Sales-
qty).
e. Display records where salesperson has achieved sales more than average sales
of all sales persons of all the regions.
Session 5:
For the following queries use Library System as created by you in earlier sessions.
You must use the query tools/ SQL/ Reports/ Forms/ Graphs/Views/ using
client/server wherever needed.
1. Get the list of books presently issued to the members, along with the names of
the book as well as names of the members.
2. Get the list of the members who
(a) are entitled for more books than that the entitlement of member name
“abc”.
(b) are issued the books for more days than the number of days for “abc”.
3. Find out the history of issuing of a list of books that has been identified during
inspection as damaged books. (Create the necessary tables if needed).
4. Create the tables Item master and Transaction having following format:
Item Master: Transaction:
Item-code item-code
Item-name Quantity
Price Date of transaction
Set the foreign key constraints in the tables and insert at least 5 records having
meaningful data. Now answer the following queries.
Session 6:
1. Create the following tables:
Order party: (Order number, Order date, customer code)
Order: Order number, Item code, Quantity
2. Create a form for storing Bio-data of students. Create the supporting tables to
store the data.
17
Lab Manual
3. Design a suitable form for storing basic information and salary details of
employees of an organisation. Design and implement the necessary tables.
Session 7:
1. Write a procedure/trigger on department code so such that the validity of the
code is checked and the name of department is automatically displayed on
selection of department code. Assume, design and create the necessary tables
and constraints.
3. Employee code must begin with ‘P’ (Permanent) or ‘T’ (Temporary) and its
second character must be a digit. Write procedure/trigger to check if the entered
value is correct.
Session 8:
1. Design a form that shows the status of books pending on a member on entering
the member-id.
2. Design a form that modifies the records of an Item Table having the fields: Item
Code, Item Name, Quantity, Price, Re-order Level.
(a) Enter the Item Code and get all the details from the tables
(b) Check if negative values are entered in the field.
3. Design the form to display the leave information of each employee following.
The validations must be made for the fields:
- Leave information of every employee must be display grouped by month
- Display total of all leave taken.
Let us now perform all the operations you have practiced till now. You must use the
query tools/ SQL/ Reports/ Forms/ Graphs/Views/ procedures/ using client/server
wherever needed.
Session 9:
1. Add one more table employee with fields employee-number, employee-name,
Basic pay, Department in the Library management system.
2. Add a new column Date of Joining in the table.
3. Modify the length of field employee name.
4. Delete the column basic from basic pay.
5. Find the details of members who were issued a book prior to Feb 1st 2005.
6. In previous query 5, list the details of the particular members.
7. In previous query 5, list the details of only two such members.
8. List the details of the persons who have been issued at least one book.
9. List the names of three persons who have not been issued any book.
10. List of members, who are entitled for 5 books or are issued the books for 15
days.
11. List the names of members in fixed length of 30 characters followed by their
codes in parenthesis and with first character of the name in capital.
12. Find the list of the members who have been issued the books having the same
ISBN number.
18
DBMS Lab
13. Display book issue/return data of various books in the following form
Book Accession number. Book Title Issued on Returned on
Session 10:
1. Create the following tables for a video library after normalizing these tables:
Customer
Customer_id Primary Key Not NULL
Name Not NULL
Area
Phone_number
Movie
Movie_no Primary Key Not NULL
Title <film title> Not NULL
Type Action or Thriller or Romance or Comedy or Suspense or
Horror etc.
Actors Not NULL
Rent-Price Not NULL
Rent applicable data part of primary key
Issues
Issue_no Primary Key Not NULL
Movie_no Refers to Movie_no of movie table
Customer_id Refers to Customer_id of Customer table
Issue_date not greater than current date.
Return_date not greater than current date.
19
Lab Manual
19. Find out the names of the movies that have been issued to the maximum number
of customers.
20. Display the month in which customers take the maximum number of movies.
21. Display the history sheet of each movie.
22. List the customers who have not been issued any movie in the last 6 months.
1.6 SUMMARY
This section has provided you with problems with respect of creation of database and
integrity using constraints and using an interface and also using SQL commands.
Some of the exercises provided include creation of forms and reports, creation of SQL
queries and an overview of various databases related concepts. We hope by now you
must be familiar with at least one database application and would be able to migrate to
other DBMSs.
20