MS Access SQL Commands
MS Access SQL Commands
Query
Language
[SQL]
What is SQL?
○ SQL stands for Structured Query Language
4
RDBMS & SQL
○ RDBMS stands for Relational Database
Management System.
5
Database Tables
6
SQL Statements
○ Using SQL statements you can do many things in
a data base.
○ The following SQL statement selects all the
records in the "Contacts" table that we saw
earlier.
7
Things to Remember
○ SQL keywords are NOT case sensitive:
8
Frequently used SQL Commands
○ SELECT - extracts data from a database
10
SQL SELECT Statement
○ The WHERE clause is used to filter records.
11
SELECT column1, column2, ...
FROM table_name;
OR
12
SELECT Column Example (10 Mins)
○ Write SQL statement to select the “Index_No" and
“Full_Name" columns from the "Contacts" table.
13
14
SELECT All Columns(05 Mins)
○ Write SQL statement to select the all columns
from the "Contacts" table.
15
SQL WHERE Clause
○ Write SQL statement to select the “Index_No" and
“Full_Name" columns from the "Contacts" table.
16
SELECT column1, column2, ...
FROM table_name
WHERE condition;
17
Where Clause (10 Mins)
○ Write SQL statement to select the “Index_No" and
“Full_Name" columns of male students from the
"Contacts" table.
18
Text vs Numeric
○ SQL requires single quotes around text values
(most database systems will also allow double
quotes).
19
Where Clause Number (05 Mins)
○ Write SQL statement to select the “Index_No" and
“Full_Name" columns of whose grade is 12 from
the "Contacts" table.
20
Operators in The WHERE Clause
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
21
Operators in The WHERE Clause
22
Where Clause Number (10 Mins)
○ Write SQL statement to select the “Index_No" and
“Full_Name" columns of whose grade between 8
and 12 from the "Contacts" table.
23
The SQL INSERT INTO Statement
○ The INSERT INTO statement is used to insert new
records in a table.
○ 01. Specify both the column names and the values to be inserted:
○ 02. Adding values for all the columns of the table, without
specifying the column names.
24
1st Method
25
2nd Method
26
INSERTING Data (10 Minutes)
○ Write SQL statement to Enter data to Subjects
table.
27
28
INSERTING Data to Specific
Columns (10 Minutes)
○ Write SQL statement to Enter data to Sub_code
and Teacher_ID in subjects table.
29
SQL Null Values
○ A field with a NULL value is a field with no value.
30
How to Find Null Values
○ It is not possible to test for NULL values with
comparison operators, such as =, <, or <>.
31
Finding Data with NULL Values
(10 Minutes)
32
33
Finding Data with NULL Values
(10 Minutes)
34
The SQL UPDATE Statement
○ The UPDATE statement is used to modify the
existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
35
Updating Data (10 Minutes)
UPDATE Subjects
SET Sub_Name = “English”,Sub_Code = “ENG111”
WHERE Subject_ID = 3;
36
SQL UPDATE – Be Careful
(10 Minutes)
○ Be careful when updating records. If you omit the
WHERE clause, ALL records will be updated!
UPDATE Subjects
SET Sub_Name =“English”; 37
The SQL DELETE Statement
○ The DELETE statement is used to delete existing
records in a table.
38
Deleting Data (10 Minutes)
40
Cont’d
41