|
| 1 | +/* |
| 2 | +
|
| 3 | +Students take courses and each student belongs to a particular department. |
| 4 | +Students grades in course are stored. Each department has large number of |
| 5 | +students and a department offers multiple courses. A course can be offered |
| 6 | +by a single department or multiple department. Draw an ERD for the stated |
| 7 | +scenario. |
| 8 | +
|
| 9 | +*/ |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +create database StudentManagementSystem |
| 15 | + |
| 16 | +use StudentManagementSystem |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +-- Create the Department table |
| 22 | +CREATE TABLE Department ( |
| 23 | + DepartmentID INT PRIMARY KEY, |
| 24 | + DepartmentName VARCHAR(255) |
| 25 | +); |
| 26 | + |
| 27 | +-- Create the Student table |
| 28 | +CREATE TABLE Student ( |
| 29 | + StudentID INT PRIMARY KEY, |
| 30 | + FirstName VARCHAR(255), |
| 31 | + LastName VARCHAR(255), |
| 32 | + DateOfBirth DATE, |
| 33 | + DepartmentID INT, |
| 34 | + FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID) |
| 35 | +); |
| 36 | + |
| 37 | +-- Create the Course table |
| 38 | +CREATE TABLE Course ( |
| 39 | + CourseID INT PRIMARY KEY, |
| 40 | + CourseName VARCHAR(255), |
| 41 | + DepartmentID INT, |
| 42 | + FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID) |
| 43 | +); |
| 44 | + |
| 45 | +-- Create the Enrollment table |
| 46 | +CREATE TABLE Enrollment ( |
| 47 | + EnrollmentID INT IDENTITY(1,1) PRIMARY KEY, |
| 48 | + StudentID INT, |
| 49 | + CourseID INT, |
| 50 | + Grade DECIMAL(4, 2), -- 1f & max value 4 |
| 51 | + FOREIGN KEY (StudentID) REFERENCES Student(StudentID), |
| 52 | + FOREIGN KEY (CourseID) REFERENCES Course(CourseID) |
| 53 | +); |
0 commit comments