0% found this document useful (0 votes)
1 views

internal dbms

The document outlines a database schema for a university system, including tables for Departments, Students, Courses, and Enrollments with their respective attributes and relationships. It includes SQL commands for creating tables, inserting data, and querying information such as student details, course names, and department statistics. Additionally, it demonstrates operations like inserting a new student and deleting a department.

Uploaded by

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

internal dbms

The document outlines a database schema for a university system, including tables for Departments, Students, Courses, and Enrollments with their respective attributes and relationships. It includes SQL commands for creating tables, inserting data, and querying information such as student details, course names, and department statistics. Additionally, it demonstrates operations like inserting a new student and deleting a department.

Uploaded by

amirbxr2003
Copyright
© © All Rights Reserved
Available Formats
Download as ZIP, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Kanishka Roll no: 2200291520094

Internal Lab DBMS

CREATE TABLE Departments (


DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(100) NOT NULL UNIQUE
);

CREATE TABLE Students (


StudentID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Age INT,
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
);

CREATE TABLE Courses (


CourseID INT PRIMARY KEY,
CourseName VARCHAR(100) NOT NULL,
Credits INT,
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
);

CREATE TABLE Enrollments (


EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
EnrollmentDate DATE,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);

INSERT INTO Departments (DepartmentID, DepartmentName)


VALUES
(1, 'CSE'),
(2, 'Electrical'),
(3, 'Mechanical'),
(4, 'Civil'),
(5, 'AI');

INSERT INTO Students (StudentID, Name, Age, DepartmentID)


VALUES
(1, 'Alice', 20, 1),
(2, 'Bob', 22, 1),
(3, 'Charlie', 21, 2),
(4, 'David', 23, 3),
(5, 'Eva', 24, 4);

INSERT INTO Courses (CourseID, CourseName, Credits, DepartmentID)


VALUES
(1, 'Database Systems', 4, 1),
(2, 'OS', 3, 1),
(3, 'DS', 4, 2),
(4, 'Java', 3, 3),
(5, 'Maths', 4, 5);

INSERT INTO Enrollments (EnrollmentID, StudentID, CourseID, EnrollmentDate)


VALUES
(1, 1, 1, '2024-01-10'),
(2, 2, 2, '2024-01-11'),
(3, 3, 3, '2024-01-12'),
(4, 4, 4, '2024-01-13'),
(5, 5, 5, '2024-01-14');

SELECT * FROM Students;

SELECT CourseName FROM Courses WHERE Credits > 3;

SELECT s.Name
FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID
WHERE c.CourseName = 'Database Systems';

SELECT d.DepartmentName, COUNT(s.StudentID) AS TotalStudents


FROM Departments d
LEFT JOIN Students s ON d.DepartmentID = s.DepartmentID
GROUP BY d.DepartmentName;

SELECT AVG(s.Age) AS AvgAge


FROM Students s
JOIN Departments d ON s.DepartmentID = d.DepartmentID
WHERE d.DepartmentName = 'CSE';

SELECT s.Name
FROM Students s
WHERE s.StudentID NOT IN (SELECT e.StudentID FROM Enrollments e);

SELECT d.DepartmentName
FROM Students s
JOIN Departments d ON s.DepartmentID = d.DepartmentID
WHERE s.Age = (SELECT MAX(Age) FROM Students);

SELECT s.Name AS StudentName, c.CourseName


FROM Students s
JOIN Enrollments e ON s.StudentID = e.StudentID
JOIN Courses c ON e.CourseID = c.CourseID;

SELECT s.Name AS StudentName, d.DepartmentName


FROM Students s
LEFT JOIN Departments d ON s.DepartmentID = d.DepartmentID;

INSERT INTO Students (StudentID, Name, Age, DepartmentID)


VALUES (1, 'New Student', 25, 1);

DELETE FROM Departments WHERE DepartmentID = 1;

You might also like