Professional Documents
Culture Documents
University of Wah
Lab 7 Manual
Applications of Information and Communication Technologies
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
3|Page
8
Lab7| Dr. Muhammad Umar Javed
4. Concept Map
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.
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):
To get back to the SQL view, press the View button in the Views group and select SQL View.
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.
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