Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

SQL

The lesson notes cover the basics of Structured Query Language (SQL) used for interacting with relational databases, detailing its key features, types of commands (DDL, DML, DQL, TCL, DCL), and syntax for various operations. Practical activities include creating a library database and writing queries to manipulate data. The session concludes with a recap of key points and a homework assignment to design a Students database.

Uploaded by

monthec39
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

SQL

The lesson notes cover the basics of Structured Query Language (SQL) used for interacting with relational databases, detailing its key features, types of commands (DDL, DML, DQL, TCL, DCL), and syntax for various operations. Practical activities include creating a library database and writing queries to manipulate data. The session concludes with a recap of key points and a homework assignment to design a Students database.

Uploaded by

monthec39
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lesson Notes: Language

Course Topic: Language


Program: Cameroon HND
Duration: 3 Hours

1. Introduction to (30 Minutes)

Definition of
 (Structured Query Language) is a standard language used to interact with
relational databases.
 It allows for:
o Data Definition: Creating and modifying database structures.
o Data Manipulation: Inserting, updating, deleting, and retrieving data.

Key Features of
1. Declarative Nature:
o Focuses on what to do rather than how to do it.
o Example: Retrieve data from a table without specifying algorithms.
2. Standardized Language:
o Supported by most relational database systems like My , Postgre , Oracle, and
Server.
3. Comprehensive:
o Includes commands for querying, updating, and managing data.

Types of Commands
1. Data Definition Language (DDL): Define and modify database structure.
o Commands: CREATE, ALTER, DROP, TRUNCATE.
2. Data Manipulation Language (DML): Work with data in tables.
o Commands: SELECT, INSERT, UPDATE, DELETE.
3. Data Query Language (DQL): Retrieve data from databases.
o Command: SELECT.
4. Transaction Control Language (TCL): Manage database transactions.
o Commands: COMMIT, ROLLBACK, SAVEPOINT.
5. Data Control Language (DCL): Control access to data.
o Commands: GRANT, REVOKE.

2. Core Concepts and Syntax (1 Hour)

2.1 Data Definition Language (DDL)


1. CREATE Command
 Used to create databases and tables.
 Syntax:

.............Code........
CREATE TABLE TableName (
Column1 DataType Constraint,
Column2 DataType Constraint
);
Example:

.............Code........
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT CHECK (Age > 0),
Department VARCHAR(50)
);

2. ALTER Command
 Used to modify an existing table.
 Syntax:

.............Code........
ALTER TABLE TableName
ADD ColumnName DataType;
Example:

.............Code........
ALTER TABLE Students
ADD Email VARCHAR(100);

3. DROP Command
 Used to delete an entire database or table.
 Syntax:

.............Code........
DROP TABLE TableName;
Example:

.............Code........
DROP TABLE Students;

2.2 Data Manipulation Language (DML)


1. SELECT Command
 Retrieve specific data from a table.
 Syntax:

.............Code........
SELECT Column1, Column2 FROM TableName
WHERE Condition;
Example:

.............Code........
SELECT Name, Age FROM Students WHERE Department = 'IT';

2. INSERT Command
 Add new records to a table.
 Syntax:

.............Code........
INSERT INTO TableName (Column1, Column2)
VALUES (Value1, Value2);
Example:

.............Code........
INSERT INTO Students (StudentID, Name, Age, Department)
VALUES (1, 'Alice', 20, 'IT');

3. UPDATE Command
 Modify existing data.
 Syntax:

.............Code........
UPDATE TableName
SET Column1 = Value1
WHERE Condition;
Example:

.............Code........
UPDATE Students
SET Age = 21
WHERE StudentID = 1;

4. DELETE Command
 Remove specific records from a table.
 Syntax:

.............Code........
DELETE FROM TableName WHERE Condition;
Example:

.............Code........
DELETE FROM Students WHERE Age < 18;

3. Practical Activities (1 Hour)

Activity 1: Database Creation and Manipulation


1. Task: Create a database for a library system and perform the following operations:
o Create a Books table with fields: BookID, Title, Author, Price.
o Add constraints: BookID as primary key, Price greater than 0.
o Insert 3 sample records.
o Update the price of one book.
Solution:

.............Code........
CREATE TABLE Books (
BookID INT PRIMARY KEY,
Title VARCHAR(100),
Author VARCHAR(100),
Price DECIMAL CHECK (Price > 0)
);

INSERT INTO Books (BookID, Title, Author, Price)


VALUES (1, 'Database Systems', 'John Doe', 50.00),
(2, ' Mastery', 'Jane Smith', 40.00),
(3, 'Advanced Databases', 'Tom Lee', 45.00);

UPDATE Books
SET Price = 55.00
WHERE BookID = 1;

Activity 2: Writing Queries


1. Task: Write queries to:
o Retrieve all books priced above 40.
o Delete a book with a specific BookID.
Solution:

.............Code........
SELECT * FROM Books WHERE Price > 40;

DELETE FROM Books WHERE BookID = 3;

4. Summary and Wrap-Up (30 Minutes)

Key Points Recap


1. is the standard language for interacting with relational databases.
2. It is divided into DDL, DML, DQL, TCL, and DCL commands.
3. Proper use of ensures efficient data handling and integrity.

Homework
1. Design a Students database with fields: StudentID, Name, Age, Department, and
Email.
o Include constraints: StudentID as primary key, Age greater than 0, and unique
Email.
o Write queries to insert data, update a record, and retrieve all students in a
specific department.

You might also like