Welcome to the SQL Tutorial for our School Management project! In this comprehensive guide, we'll be diving into the world of Structured Query Language (SQL) and creating a practical, real-world application. This tutorial is designed for both beginners and intermediate learners, so let's get started!
SQL (Structured Query Language) is a standard language for managing and manipulating databases. It's used to communicate with a database, enabling us to create, read, update, and delete data.
š” Pro Tip: SQL is essential for developers as it helps manage and analyze data efficiently.
First, let's create a database for our school management system:
CREATE DATABASE SchoolManagement;Now, let's select the database we just created:
USE SchoolManagement;Next, we'll create tables for our data. We'll need tables for Students, Teachers, Classes, and Subjects:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DOB DATE,
ClassID INT
);
CREATE TABLE Teachers (
TeacherID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
SubjectID INT
);
CREATE TABLE Classes (
ClassID INT PRIMARY KEY,
ClassName VARCHAR(50)
);
CREATE TABLE Subjects (
SubjectID INT PRIMARY KEY,
SubjectName VARCHAR(50)
);š Note: Each table has a primary key (StudentID, TeacherID, ClassID, SubjectID) to uniquely identify each record.
Now, let's insert some data into our tables:
INSERT INTO Students (StudentID, FirstName, LastName, DOB, ClassID)
VALUES (1, 'John', 'Doe', '1999-01-01', 1);
INSERT INTO Teachers (TeacherID, FirstName, LastName, SubjectID)
VALUES (1, 'Jane', 'Smith', 1);
INSERT INTO Classes (ClassID, ClassName)
VALUES (1, 'Class 1');
INSERT INTO Subjects (SubjectID, SubjectName)
VALUES (1, 'Math');Now that we have some data, let's query it!
SELECT * FROM Students;SELECT * FROM Students WHERE ClassID = 1;UPDATE Students SET DOB = '2000-01-01' WHERE StudentID = 1;DELETE FROM Students WHERE StudentID = 1;šÆ Joining Tables: We can join tables using the JOIN keyword to retrieve data from multiple tables:
SELECT Students.FirstName, Teachers.FirstName AS TeacherFirstName
FROM Students
JOIN Teachers ON Students.ClassID = Teachers.ClassID;What does SQL stand for?
What does the `JOIN` keyword in SQL do?
And there you have it! You've completed the beginner-friendly SQL tutorial for our School Management project. As you continue learning SQL, remember to practice, experiment, and explore different query types and functions. Happy coding! š¤š»š