Code of DMS

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CODE:

1. SQL SCHEMA AND TABLE


CREATION:
Crea�ng Student Table
CREATE TABLE Student (
student_id INT PRIMARY KEY AUTO_INCREMENT,
first_name
VARCHAR(50), last_name
VARCHAR(50), dob DATE,
gender VARCHAR(10),
address VARCHAR(255),
email VARCHAR(100),
phone_number VARCHAR(15)
);

-- Crea�ng Course Table


CREATE TABLE Course (
course_id INT PRIMARY KEY AUTO_INCREMENT,
course_name VARCHAR(100),
course_descrip�on TEXT,
credits INT
);

-- Crea�ng Enrollment Table (Intermediate Table for Student and Course)


CREATE TABLE Enrollment (
enrollment_id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT,
course_id INT,
grade CHAR(2),

enrollment_date DATE,

FOREIGN KEY (student_id) REFERENCES Student(student_id),

FOREIGN KEY (course_id) REFERENCES Course(course_id)

);

2. DATA INSERTION:
Inser�ng records into the Student Table
INSERT INTO Student (first_name, last_name, dob, gender, address, email, phone_number)
VALUES ('John', 'Doe', '2000-05-15', 'Male', '123 Main St, City',
'[email protected]', '1234567890');

3. INSERTING DATA INFO:


Inser�ng records into the Course Table
INSERT INTO Course (course_name, course_descrip�on,
credits) VALUES ('Mathema�cs', 'Basic math course', 3);

4. QUERYING THE DATABASE:


SELECT Student.first_name, Student.last_name, Course.course_name, Enrollment.grade
FROM Student
JOIN Enrollment ON Student.student_id = Enrollment.student_id
JOIN Course ON Course.course_id = Enrollment.course_id
WHERE Course.course_name = 'Mathema�cs';

You might also like