📘 Step 1: Create the students table
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
age INT,
gender ENUM('Male', 'Female', 'Other'),
grade VARCHAR(10)
);
Step 2: Create the courses table
CREATE TABLE courses (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
student_id INT,
FOREIGN KEY (student_id) REFERENCES students(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
Step 3: Insert data into students
INSERT INTO students (name, age, gender, grade) VALUES
('Alice', 14, 'Female', '8th'),
('Bob', 15, 'Male', '9th'),
('Diana', 14, 'Female', '8th');
Step 4: Insert data into courses
INSERT INTO courses (name, student_id) VALUES
('Mathematics', 1),
('Science', 1),
('English', 2),
('History', 3),
('Mathematics', 3);
Step 5: Fetch all courses with student names
SELECT c.id, c.name AS course_name, s.name AS student_name
FROM courses c
JOIN students s ON c.student_id = s.id;
Assigning values using SET (usually in stored procedures or scripts):
DECLARE @name VARCHAR(50);
SET @name = 'John Doe';
2. Assigning values during UPDATE:
UPDATE employees
SET salary = 50000
WHERE id = 101;
3. Assignment in SELECT using variables:
SELECT @total := SUM(price) FROM orders;
4. Inserting data with INSERT INTO:
INSERT INTO students (name, age)
VALUES ('Alice', 20);