Presentation MASTERING SQL
Presentation MASTERING SQL
PRESENTED BY
MACALIN AXMED
Presentation Objectives
• Understand the Basics of SQL • Create and Use Views
• Create and Modify Databases and • Develop and Use Stored
Tables Procedures
• Insert, Update, and Delete Data • Write and Implement Functions in
SQL
• Master Querying Data
• Implement Triggers for Data
• Understand Database Integrity
Relationships
• Understand Transactions and Data
• Perform Advanced SQL Queries Consistency
Using Joins
• Apply SQL Concepts in Real-World
Scenarios
Introduction to SQL and DBMS
SQL (Structured Query Language)
• A standardized language for managing and manipulating relational
databases.
• Used for querying (`SELECT`), inserting (`INSERT`), updating (`UPDATE`),
and deleting (`DELETE`) data.
• Works with relational database management systems (RDBMS) like MySQL,
PostgreSQL, and Oracle.
);
Common Constraints
• Types of Constraints
• NOT NULL: Ensures a column cannot store NULL values.
• UNIQUE: Ensures all values in a column are distinct.
• CHECK: Ensures a column meets a specific condition.
• PRIMARY KEY: Uniquely identifies each row in a table.
• FOREIGN KEY: Ensures referential integrity between tables.
Altering Tables
• SQL Command: ALTER TABLE
• ALTER TABLE Students ADD COLUMN address VARCHAR(50);
• ALTER TABLE Students ADD CONSTRAINT chk_age CHECK (age >= 5);
Altering Tables
• SQL Command: ALTER TABLE
• ALTER TABLE Students ADD COLUMN address VARCHAR(50);
• ALTER TABLE Students ADD CONSTRAINT chk_age CHECK (age >= 5);
Inserting Data
• SQL Command: INSERT INTO
• INSERT INTO Students (name, age, email, grade)
• VALUES ('Alice', 14, 'alice@email.com', '8th');
Updating Data
• SQL Command: UPDATE
• UPDATE Students SET age = 15 WHERE name = 'Alice';
Deleting Data
• SQL Command: DELETE
• DELETE FROM Students WHERE name = 'Alice';
Selecting Data
• SQL Command: SELECT
• SELECT FROM Students;
• SELECT name, age FROM Students;
Select with WHERE Clause
• SQL Command: SELECT ... WHERE
• SELECT name, age FROM Students WHERE age > 10;
Select with ORDER BY
• SQL Command: SELECT ... ORDER BY
• SELECT name, age FROM Students ORDER BY age DESC;
Select with LIKE
• SQL Command: SELECT ... LIKE
• SELECT name FROM Students WHERE name LIKE 'A%';
Select with BETWEEN
• SQL Command: SELECT ... BETWEEN
• SELECT name FROM Students WHERE age BETWEEN 10 AND 15;
Select with TOP
• SQL Command: SELECT ... LIMIT or TOP
• SELECT FROM Students LIMIT 5;
Aggregate Functions
• SQL Command: COUNT(), AVG(), SUM()
• SELECT COUNT() FROM Students;
• SELECT AVG(age) FROM Students;
• SELECT SUM(age) FROM Students;
One-to-One Relationships
• Example: A Student has one Profile.
• CREATE TABLE StudentProfile (
• student_id INT PRIMARY KEY,
• address VARCHAR(255),
• FOREIGN KEY (student_id) REFERENCES Students(id)
• );
One-to-Many Relationships
• Example: A Teacher teaches many Students.
• CREATE TABLE Teachers (
• id INT PRIMARY KEY AUTO_INCREMENT,
• name VARCHAR(50) NOT NULL
• );
•