You are on page 1of 12

MS ACCESS

QUERIES
MS Access - Query
• A query is a request for data results and action on data.
• You can use a query to answer a simple question, perform
calculations, combine data from different tables, or even add,
change, or delete table data.
• As tables grow in size they can have hundreds of thousands of
records, which makes it impossible for the user to pick out specific
records from that table.
• With a query you can apply a filter to the table"s data; so that you
only get the information that you want.
• In a standard Relational Database Management System (RDBMS),
queries are implemented using the commands built within the
Structured Query Language (SQL). Examples of RDBMS software
are MS-Access, MySQL, Oracle, Microsoft SQL Server.
MS Access - Query
The SQL standard has sublanguages such as:

•Data Manipulation Language (DML): SELECT


statements and action queries (DELETE, UPDATE,
INSERT INTO, ...)
•Data Definition Language (DDL): Statements
that alter the schema (changing the tables,
fields, indexes, relations, queries, etc.)
Create table (DDL)
CREATE table Teacher
( TeacherID number primary key,
TName text,
Taddress text,
Tphone number
);
Alter table (DDL)
• Alter table Teacher add salary currency;
• alter table Teacher drop salary currency;
• Alter table Teacher alter column Tphone text;

NINJA TIP: Don’t try to write more than one command on the SQL query page of MS Access.
Write one command per query object.
Drop table (DDL)
• Create table IT;
• Drop table IT;
Insert Into (DML)
• Insert into Teacher (TeacherID, TName, Taddress, Tphone) values(1, "Ms
Pooja", "Rohini", "9910350987");
• Insert into Teacher (TeacherID, TName, Taddress, Tphone) values(2, “Ms
Manvi”, “Tilak Nagar", "9999350987");
• Insert into Teacher (TeacherID, TName, Taddress, Tphone) values(3, "Ms
Tanisha", "Rohini", "8810350987");
• Insert into Teacher (TeacherID, TName, Taddress, Tphone) values(4, "Mr
Singh", "Subhash Nagar", "7778350987");
• Insert into Teacher (TeacherID, TName, Taddress, Tphone) values(5, "Mr
Jayakar", "Janakpuri", "7292036505");
NINJA TIP: Whenever you are copy-pasting the commands from any other source: Webpage/Word/ any other
place. First, paste the content into notepad and then again copy and paste it into the required command
editor/place.
Select Command (Query): DML / Query
• Select TeacherID from Teacher;
• Select TeacherID, TName, Taddress, Tphone from
Teacher;
• Select * from Teacher;
Update Command (DML)

• Update Teacher set Tphone='1234567890'


where TeacherID=3;
Delete from (DML)
• Delete from Teacher where TName = 'Ms Pooja';
Aggregate Functions

1)Count() : Select Count(*) from Teacher;


2)Sum() : Select sum(TeacherID) from Teacher;
3)Avg() : Select avg(TeacherID) from Teacher;
4)Min() : Select min(TeacherID) from Teacher;
5)Max() : SELECT Max(TeacherID) FROM Teacher;
Lab Questions and Exercises: Instructions
1. All the questions and Exercises are to be attempted in a separate Practical Exercise
Notebook for Computers (buy a standard-sized practical book with one side plain /
unruled and one side ruled, having near about 100 pages, 27-30 lines per ruled type
page).
2. It is necessary to maintain the Index on the first page of your notebook.
3. All the questions/exercises are required to be accompanied by
diagrams/figures/charts/necessary outputs related to that question/exercise.
4. Each command of SQL has to be written on the ruled side and the output of the same
has to be cut out of the printed output (hardcopy) and is required to be pasted onto the
corresponding plain/unruled side (left-side).
5. Any diagram accompanying the answer may also be drawn using pencil and scale but
output from the MS-Access has to be necessarily a hardcopy output to be pasted along
with the actual steps written on ruled side (As explained in point 3).
6. LAST DATE TO SUBMIT THE COMPLETE FILE ALONG WITH THE FILLED INDEX would be
03 November 2022.

You might also like