0% found this document useful (0 votes)
2 views4 pages

Module 7 Basic SQL Statements

Module 7 teaches the basics of SQL, focusing on creating, manipulating, and retrieving data in relational databases. It covers SQL definitions, basic concepts, and the differences between Data Definition Language (DDL) and Data Manipulation Language (DML). The module includes hands-on activities for practical application, such as creating a database for a Bookshop and performing various SQL operations.

Uploaded by

Jaw Once
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Module 7 Basic SQL Statements

Module 7 teaches the basics of SQL, focusing on creating, manipulating, and retrieving data in relational databases. It covers SQL definitions, basic concepts, and the differences between Data Definition Language (DDL) and Data Manipulation Language (DML). The module includes hands-on activities for practical application, such as creating a database for a Bookshop and performing various SQL operations.

Uploaded by

Jaw Once
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Module 7: BASIC SQL STATEMENTS FOR STORING AND RETRIEVING DATA IN A RELATIONAL

DATABASE

Objective:

By the end of this lesson, learners will be able to:

1. Understand the basics of SQL (Structured Query Language).


2. Perform simple database operations like creating tables, inserting data, querying data,
updating records, and deleting records.
3. Understand how to use SQL statements for data manipulation and retrieval.

1. What is SQL?

Definition: SQL (Structured Query Language) is the standard language used for managing
and manipulating relational databases.

Purpose: It allows users to p erform tasks such as querying data,


updating records, creating and modifying databases, and managing user permissions.

2. Basic Concepts:
a. Database
i. A collection of data organized in tables.
ii. Tables contain rows (records) and columns (fields).
b. Tables
i. The basic unit of a database where data is stored.
ii. Tables are made up of rows (records) and columns (fields).
c. SQL Statements
i. SQL commands that are used to interact with the database. These include:
1. Data Definition Language (DDL): Defines the structure of the
database (e.g., CREATE, ALTER, DROP).
2. Data Manipulation Language (DML): Manages data within tables
(e.g., SELECT, INSERT, UPDATE, DELETE)
ii. Difference between DDL and DML
1. DDL (Data Definition Language)
a. DDL is used to define, modify, and remove database
structures (such as tables, indexes, and schemas). It deals
with the structure of the database rather than the data
within it.
b. Common DDL Commands:
i. CREATE: Used to create database objects like tables,
views, and indexes.
ii. ALTER: Used to modify an existing database object,
such as adding or dropping columns from a table.
iii. DROP: Used to delete database objects, such as a
table or a view.
iv. TRUNCATE: Used to remove all rows from a table,
but the table structure remains.
c. Examples:
i. CREATE TABLE: Creates a new table.
ii. ALTER TABLE: Modifies an existing table's
structure.
iii. DROP TABLE: Deletes a table from the database.
d. Key Points:
i. DDL changes the structure of the database.
ii. DDL operations are typically permanent and
irreversible (e.g., dropping a table).
iii. DDL commands don’t operate on data itself, but
rather on the schema.
2. DML (Data Manipulation Language)
a. DML is used to manipulate data within the existing
structures (tables) in a database. It focuses on the contents
of the database.
b. Common DML Commands:
i. SELECT: Retrieves data from a table.
ii. INSERT: Adds new rows of data into a table
iii. UPDATE: Modifies existing data in a table.
iv. DELETE: Removes data from a table.
c. Examples
i. SELECT: Retrieves rows from a table.
ii. INSERT: Adds new rows of data to a table.
iii. UPDATE: Modifies existing rows of data.
iv. DELETE: Deletes specific rows of data from a table.
d. Key points
i. DML works with the data within the database.
ii. DML operations can often be rolled back (undone) if
a transaction is not yet committed (depending on
the DBMS and transaction handling).
iii. DML commands do not affect the database schema,
just the data within tables.
3. Why Do Databases Have DDL and DML?
a. Having these two distinct languages allows for a clear
division of roles and tasks in managing a database, making it
more secure, efficient, and maintainable.
3. SQL Syntax and Structure
a. SQL queries generally follow this structure:

 Commands: SELECT, INSERT, UPDATE, DELETE, etc.


 Operations: Actions like selecting, inserting, etc.
 Conditions: Used to filter results (e.g., WHERE).
 Order: Sorting results (e.g., ORDER BY).
4. Basic SQL Operations
a. Creating a Table
b. Inserting Data into a Table
i. To insert data into a table:

ii. Example

c. Querying Data (SELECT)


i. To retrieve data from a table:

ii. Example

iii. To retrieve all columns:

d. Filtering Data (WHERE Clause)


i. To filter data:

ii. You can also use logical operators:

e. Sorting Data (ORDER BY Clause)


i. To sort results:

f. Updating Data (UPDATE)


i. To modify existing records:
g. Deleting Data (DELETE)
i. To delete records:

--- questions ---

Hands-On Activity (PhyMyAdmin)

1. Create a database for Bookshop: Create a table named Books with columns: book_id,
title, author, year_published, and price.
2. Insert Data into the Books Table: Add at least seven books into the Books table.
3. Query All Books: Write a query to retrieve all information from the Books table.
4. Update Book Price: Change the price of a specific book.
5. Delete a Book: Delete a book from the Books table based on its book_id.
6. Find Books Published After 2010: Retrieve all books published after the year 2010.
7. Submission: Export and upload your output in the Google Drive Link provided.
8. Provide an ERD for this task.

You might also like