You are on page 1of 10

8

Lab7| Dr. Muhammad Umar Javed

University of Wah

Lab 7 Manual
Applications of Information and Communication Technologies

Course Instructor Dr. Muhammad Umar Javed

Lab Instructor(s) Dr. Muhammad Umar Javed

Semester Fall 2023

1|Page
8
Lab7| Dr. Muhammad Umar Javed

Table of Contents
Task List .........................................................................................................................
Task-1 Introduction to SQL ............................................................................................... 3
Task-2 Importing Excel Data into Access ............................................................................... 4
Task-3 Using SQL Language and Clauses ............................................................................... 7
Task-4 Creating an Access Report ....................................................................................... 12

2|Page
8
Lab7| Dr. Muhammad Umar Javed

Week-07
Lab 07: SQL in MS Access
1. Introduction
The fundamental job of an MS Access database (or indeed any database) is to provide a home (base) for
data (data). Hence database. Data is stored in entities which are referred to in MS Access as tables and this
ability to store data provides us with an opportunity to read, update, insert and delete said data later. To
work with the data we have stored, we need to be able to communicate with the database. And to
communicate with the database, we need to use Structured Query Language (SQL).
SQL provides us with the opportunity to read data from single or even multiple tables. We can use SQL to
sum, count or average values stored in the database. SQL can also be used to insert new records, update
existing ones, and delete unwanted ones.
In MS Access, every communication with the database uses SQL to some degree although this is not always
obvious. When you create a form based off a table, the form is using SQL to communicate with the table,
but these interactions are buried inside MS Access.
It is worth remembering that the fundamental purpose of a database is to store and manipulate data. At the
very basic level there are four actions that a database is required to perform. These activities are often
referred to as CRUD operations. CRUD stands for Create, Read, Update and Delete.

2. Activity Time-boxing
Table 1-Activity Time-boxing

Task No. Activity Name Activity Time Total Time


5.1 Solution Modelling 20 mins 20 mins
6.2 Setting up Browser 5 mins 5 mins
6.3 Walkthrough Task 35 mins 35 mins
7 Practice Tasks 10+10+15 (mins) 35 mins
8 Evaluation Task 60 mins for all tasks 60 mins
Total Time 155 mins

3. Objective(s) of the Experiment


After performing this lab, students shall be able to:
 Import Excel data into Access
 Understand what Structured Query Language is
 Run SQL Data retrieval commands in Access

3|Page
8
Lab7| Dr. Muhammad Umar Javed

4. Concept Map

4.1. Importing Excel data into Access:


Sometimes you start out with a small table in Excel and before you know it, your dataset gets so large that
it becomes more manageable if you turn it into a database. This is why it can be useful to import Excel
sheets into Access.
We will be importing the file AccessLab4.xslx into a new Database file. Open Microsoft Access and create
a new database. In the External Data tab, press the New Data Source and then From File and then click on
the Excel button from the Import & Link group.
Browse to where your file “AccessLab4.xslx” file and press OK.

Select the First Row Contains Column Headings checkbox and press Next. This will set our column
headings as field names in the table that will be created.

4|Page
8
Lab7| Dr. Muhammad Umar Javed

Next dialog box allows you to set data types of fields. Select the Serial No. field from the table and change
its data type to Integer. Press Next.

The next screen allows us to create a new primary key. The choices are: Let Access add primary key, I
Choose my own primary key, or no primary key. In this case, we will let Access create a new field for the
primary key. Press Next.

5|Page
8
Lab7| Dr. Muhammad Umar Javed

Name your table as Data and then click on the Finish button.

6|Page
8
Lab7| Dr. Muhammad Umar Javed

Next, Access will ask if you want to save the import steps. Press the Close button.
The following is what the Data table looks like.

4.2. SELECT Queries:


The SELECT statement is the most basic phrase in the Structured Query Language (SQL). Let us make a
query that returns all records from a table using SQL. Open file imported in the previous section and then
click on Query Design. To go to the SQL view, click on the “View” and then the button labeled SQL in the
Results group.
Since we are creating a SELECT query, Access knows enough to start it out for us.

For example: To get a query that shows all the records and fields in a file named “Data”, type in (do not
forget the semicolon):

SELECT * FROM Data;


7|Page
8
Lab7| Dr. Muhammad Umar Javed

Then run the query. Following is the result of the query.

To get back to the SQL view, press the View button in the Views group and select SQL View.

4.3. The WHERE Clause:


The WHERE clause in an SQL SELECT query provides a similar function to the Criteria field in the Access
query Design View. WHERE allows you to set criteria that must be met by the records to be shown in the
query result. WHERE also allows you to set relationships between fields in your queries.
Create a new query and open its SQL view. Let us create a query that returns the NAME of student having
registration no “UW-19-CS-BS-075”. Type in:
SELECT Name FROM Data
WHERE Registration_No = "UW-19-CS-BS-075";

Then run the query.

8|Page
8
Lab7| Dr. Muhammad Umar Javed

Now let us get back to the query that was created previously. You will notice that the query result is listing
the name of only that student whose registration number is 75. This is because the query does not consider
the relationships between the tables.

5. Create the Table using SQL


Create the following table and write SQL select commands as given above.

Practice Task 1
Write an SQL data retrieval command to display only the data of Registration_No UW-19-CS-BS-013
and UW-19-CS-BS-039.

Practice Task 2
Write an SQL data retrieval command to display the registration number, Name, and time slot against
Name “Natasha Bibi”.

9|Page
8
Lab7| Dr. Muhammad Umar Javed

Practice Task 3
Perform the following tasks:
1.1. Create a query in SQL that shows only “Name” from Data.
1.2. Create a query in SQL that displays a title “Name” along with Registration Number and its
scheduled time for viva voce.
1.3. Create a query that displays the registration number of a student named “AQEEL ZAFFAR”.
1.4. Modify the query written in Task 8.3 using SQL and show the registration number of the student
where name = “AQEEL ZAFFAR” and scheduled time slot = “2:00-2:15”.

10 | P a g e

You might also like