Chapter-5 SQL
Chapter-5 SQL
Chapter-5 SQL
1 04/04/2024
Chapter Five
2 04/04/2024
What is SQL?
3 04/04/2024
What Can SQL do?
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views
4 04/04/2024
RDBMS
RDBMS is the basis for SQL, and for all modern database systems such as MS
SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
The data in RDBMS is stored in database objects called tables.
A table is a collection of related data entries and it consists of columns and rows.
5 04/04/2024
SQL Commands
6 04/04/2024
Data Definition Language (DDL)
7 04/04/2024
Data Manipulation Language (DML)
8 04/04/2024
Data Control Language (DCL)
9 04/04/2024
SQL Data Types for Various DBs
10 04/04/2024
Database SQL Syntax
Tables
A database most often contains one or more tables. Each table is
identified by a name (e.g. "Customers" or "Orders"). Tables contain
records (rows) with data.
Sample database (included in MS Access and MS SQL Server).
Below is a selection from the "Customers" table:
11 04/04/2024
Customers table
12 04/04/2024
cont’d…
13 04/04/2024
SQL Statements
14 04/04/2024
Semicolon after SQL Statements?
15 04/04/2024
Some of The Most Important SQL Commands
16 04/04/2024
SQL SELECT Statement
and
17 04/04/2024
SELECT Column Example
Example:
18 04/04/2024
SELECT * Example
Example:
19 04/04/2024
SQL SELECT DISTINCT statement
20 04/04/2024
SQL SELECT DISTINCT Syntax
SELECT
DISTINCT column_name,column_n
ame
FROM table_name;
21 04/04/2024
SQL
The WHERE WHERE
clause Clause
is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified
criterion.
SQL WHERE Syntax
SELECT column_name,column_name
FROM table_name
WHERE column name operator value;
22 04/04/2024
WHERE Clause Example
23 04/04/2024
SQL AND & OR Operators
24 04/04/2024
AND Operator Example
The following SQL statement selects all customers from the country
Example:
25 04/04/2024
OR Operator Example
Example:
26 04/04/2024
Combining AND & OR
You can also combine AND OR (use parenthesis to form complex expressions).
The following SQL statement selects all customers from the country "Germany"
AND the city must be equal to "Berlin" OR "München", in the "Customers" table:
Example:
27 04/04/2024
SQL CREATE TABLE Statement
28 04/04/2024
Cont’d…
SQL CREATE TABLE Syntax
29 04/04/2024
Cont’d…
30 04/04/2024
SQL CREATE TABLE Example
31 04/04/2024
SQL INSERT INTO Statement
32 04/04/2024
cont’d…
33 04/04/2024
It is alsoInsert
possibleData
to onlyOnly
insertin Specified
data in specificColumns
columns.
The following SQL statement will insert a new row, but only insert data in the
"CustomerName", "City", and "Country" columns (and the CustomerID field will of
course also be updated automatically):
34 04/04/2024
The SQL UPDATE Statement
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
35 04/04/2024
SQL UPDATE Example
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
36 04/04/2024
SQL DELETE Statement
37 04/04/2024
SQL DELETE Example
38 04/04/2024
Delete All Data
It is possible to delete all rows in a table without deleting the table.
This means that the table structure, attributes, and indexes will be
intact:
39 04/04/2024
SQL LIKE Operator
40 04/04/2024
SQL LIKE Operator Examples
Example
41 04/04/2024
cont’d…
Example
42 04/04/2024
The SQL BETWEEN Operator
43 04/04/2024
BETWEEN Operator Example
Example
44 04/04/2024
BETWEEN Operator with Text Value
Example
45 04/04/2024
End of chapter five………
?
46 04/04/2024