Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Introduction to Information System 2023/2024 Handout: Lab 6

Lab 6
Lap contents:
➢ Queries
− What is query?
− Types of Queries (Select, Action, etc.)
➢ How to create Query Design?
➢ Action Query
− Append/Insert Query (Datasheet view & Query Design SQL view)
− Delete Query (Datasheet view & Query Design SQL view)

Query
• An object that provides a custom view of data from one or more tables.
• Refers to a data retrieval, insertion, update, or deletion operation performed
on a database.
• Queries are used to search for specific information based on a set of
conditions and criteria specified by the user.

Query Type:
When you want to create a new query in Access, start by deciding the type of
query you need. The most common types are:
• Select Query: Retrieves data from one or more tables and displays the
results in a datasheet.
• Action Query: Includes Append, Update, Delete, and Make Table Queries.
These modify or move data from one or more tables.

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


Action Query (Insert into data)
Method 1: Datasheet View
1) Open Your Table: Open the table where you want to insert the data
2) Navigate to Datasheet View: Click on the "View" button in the ribbon at the top of the
Access window and select "Datasheet View". Alternatively, you can double-click on the
table name in the navigation pane to open it directly in Datasheet View.
3) Go to the Last Row: Scroll to the last row of the table. You should see an empty row at
the bottom where you can input new data.
4) Enter Data: Click on the first cell in the empty row and start typing to enter data. Press
Tab to move to the next field or Shift+Tab to move to the previous field. You can also
use the arrow keys to navigate between fields.
5) Save Your Changes: After entering the data, either click on another row or press Enter to
save the data.

Patients Table

Doctors Table:

Appointments Table:

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


DoctorPatient Table:

Method 2: Query Design (SQL view)


• What is SQL?
▪ SQL stands for "Structured Query Language"
▪ SQL is a query language that allows you to interact with data in a
database in an organized and efficient way.
▪ SQL is a query language that allows you to perform various
operations ( Insert , Delete , Update, Retrieve ) on data stored in a
database.

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


Steps to create query design using SQL view (insert & delete record)
1) From Create go to Query Design

2) Right-Click to query1 select SQl View

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


If you want to insert new records in a table, use the INSERT INTO
statement
INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two ways:

1) Specify both the column names and the values to be inserted:


INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


2) When adding values for all table columns, you can skip specifying column
names, but ensure the values are in the correct order corresponding to the
table columns.
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


Action Query(Delete data)
Method 1: Datasheet View
Direct Deletion: You can delete records directly from a table. In Datasheet View,
you can select one or more records and press the Delete key on your keyboard. A
confirmation dialog box will appear, asking if you're sure you want to delete the
selected records. If you confirm, the records will be permanently removed from the
table. Or Right-click Delete record

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


Method 2: Query Design(SQL view)
1) From Create go to Query Design

2) Right-Click to query1 select SQl View

3) Delete select keyword

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


If you want to delete existing record in a table, use the DELETE FROM
statement
DELETE FROM Syntax
1) If you want to delete specific record use:
DELETE FROM table_name WHERE condition;

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled


2) If you want to delete all records in the table use
DELETE FROM table_name;

Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled

You might also like