Sql_Adv_Proj

πŸ—„οΈ Examination Management System - Database Documentation

![SQL Server](https://img.shields.io/badge/SQL%20Server-2019+-CC2927?style=for-the-badge&logo=microsoft-sql-server&logoColor=white) ![Database](https://img.shields.io/badge/Database-db-blue?style=for-the-badge) ![Tables](https://img.shields.io/badge/Tables-11-green?style=for-the-badge) ![Stored Procedures](https://img.shields.io/badge/Stored_Procedures-45+-purple?style=for-the-badge) **Complete database documentation for the Examination Management System**

πŸ“‹ Table of Contents


🎯 Overview

The Examination Management System Database is a comprehensive SQL Server database designed to manage educational institution operations including:


πŸ”§ Database Information

Property Value
Database Name db
Compatibility Level SQL Server 2019 (150)
Collation DATABASE_DEFAULT
Recovery Model FULL
File Growth 64 MB
Auto Close ON

πŸ“Š Entity Relationship Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   department    β”‚
│─────────────────│
β”‚ PK departmentid β”‚
β”‚    departmentnameβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ 1:N
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     track       β”‚          β”‚   instructor    β”‚
│─────────────────│          │─────────────────│
β”‚ PK trackid      β”‚          β”‚ PK instructorid β”‚
β”‚    trackname    β”‚          β”‚    instructornameβ”‚
β”‚ FK deptid ──────┼──────────│    email        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚    password     β”‚
         β”‚                   β”‚ FK deptid ───────
         β”‚ 1:N               β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚ 1:N
β”‚    student      β”‚                   β–Ό
│─────────────────│          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PK studentid    β”‚          β”‚     course      β”‚          β”‚     topic       β”‚
β”‚    studentname  β”‚          │─────────────────│          │─────────────────│
β”‚    email (UQ)   β”‚          β”‚ PK courseid     │◄─────────│ PK topicid      β”‚
β”‚    password     β”‚          β”‚    coursename   β”‚          β”‚    topicname    β”‚
β”‚ FK trackid ──────          β”‚ FK instructorid β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚ FK topicid      β”‚
         β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                            β”‚
         β”‚                            β”‚ 1:N
         β”‚                            β–Ό
         β”‚                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                   β”‚    question     │──────────│     choice      β”‚
         β”‚                   │─────────────────│   1:N    │─────────────────│
         β”‚                   β”‚ PK questionid   β”‚          β”‚ PK choiceid     β”‚
         β”‚                   β”‚    questiontext β”‚          β”‚    choicelabel  β”‚
         β”‚                   β”‚    questiontype β”‚          β”‚    choicetext   β”‚
         β”‚                   β”‚    correctanswerβ”‚          β”‚ FK questionid   β”‚
         β”‚                   β”‚    degree       β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                   β”‚ FK courseid     β”‚
         β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                            β”‚
         β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚         β”‚                                     β”‚
         β”‚         β–Ό                                     β–Ό
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  β”‚      exam       β”‚                 β”‚     examquestion        β”‚
         β”‚  │─────────────────│                 │─────────────────────────│
         └─►│ PK examid       │◄────────────────│ PK,FK examid            β”‚
            β”‚ FK courseid     β”‚                 β”‚ PK,FK questionid        β”‚
            β”‚ FK studentid    β”‚                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚    grade        β”‚
            β”‚    ExamStartedAtβ”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β”‚ 1:N
                     β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  studentquestionanswer  β”‚
            │─────────────────────────│
            β”‚ PK,FK examid            β”‚
            β”‚ PK,FK studentid         β”‚
            β”‚ PK,FK questionid        β”‚
            β”‚    studentanswer        β”‚
            β”‚    mark                 β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Tables

1. department

Stores academic department information.

Column Data Type Nullable Description
departmentid INT NO Primary Key - Unique department identifier
departmentname VARCHAR(100) YES Name of the department

Example Data:

| departmentid | departmentname      |
|--------------|---------------------|
| 1            | Computer Science    |
| 2            | Information Systems |
| 3            | Software Engineering|

2. track

Represents learning tracks/specializations within departments.

Column Data Type Nullable Description
trackid INT NO Primary Key - Unique track identifier
trackname VARCHAR(100) YES Name of the track
deptid INT YES Foreign Key β†’ department.departmentid

Relationships:

Example Data:

| trackid | trackname           | deptid |
|---------|---------------------|--------|
| 1       | Web Development     | 1      |
| 2       | Mobile Development  | 1      |
| 3       | Data Science        | 2      |

3. student

Stores student information and credentials.

Column Data Type Nullable Constraints Description
studentid INT IDENTITY(1,1) NO Primary Key Auto-generated student ID
studentname VARCHAR(100) YES Β  Full name of student
email VARCHAR(100) NO Unique Student email (login)
trackid INT YES Foreign Key Track assignment
password VARCHAR(50) NO Β  Account password

Relationships:

Constraints:


4. instructor

Stores instructor/teacher information.

Column Data Type Nullable Description
instructorid INT NO Primary Key - Instructor identifier
instructorname VARCHAR(100) YES Full name
email VARCHAR(100) YES Email address (login)
deptid INT YES Foreign Key β†’ department.departmentid
password VARCHAR(50) NO Account password

Relationships:


5. topic

Categorizes courses by subject/topic.

Column Data Type Nullable Description
topicid INT NO Primary Key - Topic identifier
topicname VARCHAR(100) YES Topic/subject name

Example Data:

| topicid | topicname          |
|---------|--------------------|
| 1       | Programming        |
| 2       | Database           |
| 3       | Networking         |

6. course

Stores course information with instructor and topic assignments.

Column Data Type Nullable Description
courseid INT IDENTITY(1,1) NO Primary Key - Auto-generated
coursename VARCHAR(100) YES Course title
instructorid INT YES Foreign Key β†’ instructor.instructorid
topicid INT YES Foreign Key β†’ topic.topicid

Relationships:


7. question

Stores the question bank with MCQ and True/False questions.

Column Data Type Nullable Description
questionid INT NO Primary Key - Question identifier
questiontext VARCHAR(MAX) YES The question text
questiontype VARCHAR(50) YES Type: 'MCQ' or 'TF'
correctanswer VARCHAR(100) YES Correct answer (e.g., β€˜A’, β€˜B’, β€˜True’, β€˜False’)
degree INT YES Points/marks for the question
courseid INT YES Foreign Key β†’ course.courseid

Relationships:

Question Types:


8. choice

Stores answer choices for MCQ questions.

Column Data Type Nullable Description
choiceid INT NO Primary Key - Choice identifier
choicelabel VARCHAR(10) YES Choice label (A, B, C, D)
choicetext VARCHAR(200) YES Choice text/content
questionid INT YES Foreign Key β†’ question.questionid

Relationships:

Example Data:

| choiceid | choicelabel | choicetext              | questionid |
|----------|-------------|-------------------------|------------|
| 1        | A           | JavaScript              | 1          |
| 2        | B           | Python                  | 1          |
| 3        | C           | Java                    | 1          |
| 4        | D           | All of the above        | 1          |

9. exam

Stores exam instances for students.

Column Data Type Nullable Default Description
examid INT NO Β  Primary Key - Exam identifier
courseid INT YES Β  Foreign Key β†’ course.courseid
studentid INT YES Β  Foreign Key β†’ student.studentid
grade INT YES NULL Final grade (0-100)
ExamStartedAt DATETIME2(7) NO SYSUTCDATETIME() Exam start timestamp (UTC)

Relationships:

Notes:


10. examquestion

Junction table linking exams to their questions.

Column Data Type Nullable Description
examid INT NO Primary Key (Composite), Foreign Key β†’ exam.examid
questionid INT NO Primary Key (Composite), Foreign Key β†’ question.questionid

Relationships:


11. studentquestionanswer

Stores student answers for each question in an exam.

Column Data Type Nullable Description
examid INT NO Primary Key (Composite), FK β†’ exam.examid
studentid INT NO Primary Key (Composite)
questionid INT NO Primary Key (Composite), FK β†’ question.questionid
studentanswer VARCHAR(100) YES Student’s answer (e.g., β€˜A’, β€˜True’)
mark INT YES 1 = Correct, 0 = Wrong, NULL = Not graded

Relationships:


πŸ”— Relationships

Foreign Key Summary

Child Table Column Parent Table Parent Column On Delete
track deptid department departmentid SET NULL
student trackid track trackid SET NULL
instructor deptid department departmentid SET NULL
course instructorid instructor instructorid SET NULL
course topicid topic topicid SET NULL
question courseid course courseid CASCADE
choice questionid question questionid CASCADE
exam studentid student studentid NO ACTION
examquestion examid exam examid CASCADE
examquestion questionid question questionid CASCADE
studentquestionanswer examid exam examid CASCADE
studentquestionanswer questionid question questionid CASCADE

πŸ“¦ Stored Procedures

CRUD Operations

Department Operations

Procedure Parameters Description
insert_department @deptId, @deptname Insert new department
select_department @deptId (optional) Get all or specific department
update_department @deptId, @deptName Update department name
delete_department @deptId Delete department

Track Operations

Procedure Parameters Description
insert_track @trackId, @trackName, @deptid Insert new track
select_track @trackId (optional) Get all or specific track
update_track @trackId, @trackName, @deptId Update track
delete_track @trackId Delete track

Student Operations

Procedure Parameters Description
insert_student @studentname, @email, @trackid, @password Register new student
select_student @studentid (optional) Get all or specific student
update_student @studentid, @studentname, @email, @trackid Update student info
delete_student @studentid Delete student

Instructor Operations

Procedure Parameters Description
insert_instructor @instructorid, @instructorname, @email, @deptid Add instructor
select_instructor @instructorid (optional) Get all or specific instructor
delete_instructor @instructorid Delete instructor

Topic Operations

Procedure Parameters Description
insert_topic @topicId, @topicname Insert new topic
select_topic @topicId (optional) Get all or specific topic
update_topic @topicID, @topicName Update topic
delete_topic @topicID Delete topic

Course Operations

Procedure Parameters Description
insert_course @coursename, @instructorid, @topicid Create course
select_course @courseid, @PageNumber, @PageSize Get courses (paginated)
update_course @courseid, @coursename, @instructorid, @topicid Update course
delete_course @courseid Delete course

Question Operations

Procedure Parameters Description
insert_question @questionid, @questiontext, @questiontype, @correctanswer, @degree, @courseid Add question
select_question @questionid (optional) Get questions
update_question All fields Update question
delete_question @questionid Delete question

Choice Operations

Procedure Parameters Description
insert_choice @choiceid, @choicelabel, @choicetext, @questionid Add choice
select_choice @choiceid (optional) Get choices
update_choice All fields Update choice
delete_choice @choiceid Delete choice

Authentication Procedures

sp_StudentLogin

Authenticates a student and returns their profile with enrolled courses.

EXEC sp_StudentLogin @email = 'student@example.com', @password = 'password123'

Parameters:

Parameter Type Description
@email VARCHAR(100) Student email
@password VARCHAR(100) Student password

Returns (2 Result Sets):

  1. Student Profile:
    • studentid, studentname, email, departmentname, trackname
    • StatusMessage: β€˜Success’, β€˜Email not found’, or β€˜Wrong password’
    • Success: 1 or 0
  2. Enrolled Courses:
    • courseid, coursename, departmentname, instructorname

sp_InstructorLogin

Authenticates an instructor and returns their profile.

EXEC sp_InstructorLogin @email = 'instructor@example.com', @password = 'password123'

Parameters:

Parameter Type Description
@email VARCHAR(100) Instructor email
@password VARCHAR(50) Instructor password

Returns:


Exam Management Procedures

generate_exam

Generates a new exam with random MCQ and True/False questions.

EXEC generate_exam 
    @courseID = 11, 
    @studentID = 1, 
    @mcqCount = 6, 
    @TFCount = 4

Parameters:

Parameter Type Default Description
@courseID INT Required Course to generate exam for
@studentID INT Required Student taking the exam
@mcqCount INT Required Number of MCQ questions
@TFCount INT Required Number of True/False questions
@Count INT 10 Total questions (must equal mcqCount + TFCount)

Business Logic:

  1. Validates that mcqCount + TFCount = 10
  2. Generates unique examid
  3. Randomly selects MCQ questions from course
  4. Randomly selects TF questions from course
  5. Creates studentquestionanswer records for each question
  6. Sets ExamStartedAt to current UTC time

Returns:

| Status | StatusMessage              | ExamID | StudentID |
|--------|----------------------------|--------|-----------|
| 1      | Exam generated successfully| 101    | 1         |

getexamquestions

Retrieves all questions and choices for an exam.

EXEC getexamquestions @examid = 101

Returns:

| questionid | questiontext        | questiontype | choicelabel | choicetext |
|------------|---------------------|--------------|-------------|------------|
| 1          | What is JavaScript? | MCQ          | A           | A language |
| 1          | What is JavaScript? | MCQ          | B           | A framework|
| 2          | SQL is a language   | TF           | NULL        | NULL       |

exam_answers

Submits student answers for an exam (10 answers).

EXEC exam_answers 
    @examID = 101,
    @studentID = 1,
    @ans1 = 'A',
    @ans2 = 'B',
    @ans3 = 'True',
    @ans4 = 'C',
    @ans5 = 'False',
    @ans6 = 'A',
    @ans7 = 'D',
    @ans8 = 'True',
    @ans9 = 'B',
    @ans10 = 'A'

Parameters:

Parameter Type Default Description
@examID INT Required Exam identifier
@studentID INT Required Student identifier
@ans1 - @ans10 VARCHAR(10) ’’ Answers in order

exam_correction

Grades the exam and calculates final score.

EXEC exam_correction @examID = 101, @studentID = 1

Business Logic:

  1. Compares student answers with correct answers
  2. Sets mark = 1 for correct, 0 for wrong
  3. Calculates total marks Γ— 10 = grade
  4. Updates exam.grade

Returns:

| Status | StatusMessage                          | Grade | studentID | examID |
|--------|----------------------------------------|-------|-----------|--------|
| 1      | Exam corrected and Marks added...     | 80    | 1         | 101    |

GetExamReview_Split

Returns detailed exam review with questions and choices.

EXEC GetExamReview_Split @examID = 101, @studentID = 1

Returns (2 Result Sets):

  1. Question Details:
    | questionid | questiontext | SelectedLabel | CorrectLabel | mark |
    |------------|--------------|---------------|--------------|------|
    | 1          | What is...   | A             | A            | 1    |
    | 2          | SQL is...    | True          | True         | 1    |
    
  2. Choice Map:
    | questionid | choicelabel | choicetext          |
    |------------|-------------|---------------------|
    | 1          | A           | A programming lang  |
    | 1          | B           | A markup language   |
    

GetStudentExamsHistory

Retrieves all exams taken by a student.

EXEC GetStudentExamsHistory @studentID = 1

Returns:

| examid | coursename | grade | ExamStartedAt            |
|--------|------------|-------|--------------------------|
| 101    | JavaScript | 80    | 2026-01-23T10:30:00.000Z |
| 100    | SQL        | 70    | 2026-01-22T09:00:00.000Z |

GetExamStartTime

Returns when an exam was started (for timer calculation).

EXEC GetExamStartTime @examID = 101, @studentID = 1

Returns:

| examid | ExamStartedAt            |
|--------|--------------------------|
| 101    | 2026-01-23T10:30:00.000Z |

πŸ” Constraints & Indexes

Primary Keys

Table Constraint Name Column(s)
department PK (Clustered) departmentid
track PK (Clustered) trackid
student PK_student studentid
instructor PK (Clustered) instructorid
topic PK (Clustered) topicid
course PK__course__2AAB4BC9279D1F4D courseid
question PK (Clustered) questionid
choice PK (Clustered) choiceid
exam PK (Clustered) examid
examquestion PK (Clustered) examid, questionid
studentquestionanswer PK (Clustered) examid, studentid, questionid

Unique Constraints

Table Constraint Name Column
student UQ_Student_Email email

Default Constraints

Table Constraint Name Column Default Value
exam DF_ExamStartedAt ExamStartedAt SYSUTCDATETIME()

πŸ“‹ Business Rules

Exam Generation Rules

  1. Question Count: Total must equal 10 (MCQ + TF)
  2. Random Selection: Questions selected randomly using NEWID()
  3. Course Specific: Questions come from the specified course only
  4. Unique Questions: Each question appears only once per exam
  5. Auto Timestamp: ExamStartedAt set automatically on generation

Exam Timing Rules

  1. Duration: 15 minutes from ExamStartedAt
  2. Time Calculation: Frontend calculates remaining time from ExamStartedAt
  3. Late Submission: Backend can mark as timed out if submitted after 15 minutes

Grading Rules

  1. Points: Each question worth 10 points (10 questions Γ— 10 = 100 max)
  2. Binary Marking: mark = 1 (correct) or 0 (wrong)
  3. Grade Calculation: SUM(mark) Γ— 10
  4. Pass/Fail: Typically 60+ is passing (configurable)

Answer Format

Question Type Valid Answers
MCQ β€˜A’, β€˜B’, β€˜C’, β€˜D’
TF β€˜True’, β€˜False’, β€˜T’, β€˜F’

πŸš€ Setup Instructions

Prerequisites

Installation Steps

  1. Connect to SQL Server
    -- Connect using SSMS or sqlcmd
    sqlcmd -S localhost -E
    
  2. Execute the Script
    -- Run the db.script file
    :r "path/to/db.script"
    

    Or in SSMS:

    • Open db.script
    • Press F5 to execute
  3. Verify Installation
    USE db;
    GO
       
    -- Check tables
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';
       
    -- Check procedures
    SELECT name FROM sys.procedures;
    
  4. Insert Sample Data (Optional)
    -- Insert department
    EXEC insert_department @deptId = 1, @deptname = 'Computer Science';
       
    -- Insert track
    EXEC insert_track @trackId = 1, @trackName = 'Web Development', @deptid = 1;
       
    -- Insert student
    EXEC insert_student 
        @studentname = 'John Doe', 
        @email = 'john@example.com', 
        @trackid = 1, 
        @password = 'password123';
    

Backup Files

The project includes backup files for quick restoration:

Restore Command:

RESTORE DATABASE db 
FROM DISK = 'path/to/dbafterstored.bak'
WITH REPLACE,
MOVE 'db' TO 'D:\SQL_Server\...\db.mdf',
MOVE 'db_log' TO 'D:\SQL_Server\...\db_log.ldf';

πŸ“Š Sample Queries

Get Student with Track and Department

SELECT 
    s.studentid,
    s.studentname,
    s.email,
    t.trackname,
    d.departmentname
FROM student s
LEFT JOIN track t ON s.trackid = t.trackid
LEFT JOIN department d ON t.deptid = d.departmentid;

Get Course with Instructor and Topic

SELECT 
    c.courseid,
    c.coursename,
    i.instructorname,
    t.topicname
FROM course c
LEFT JOIN instructor i ON c.instructorid = i.instructorid
LEFT JOIN topic t ON c.topicid = t.topicid;

Get Exam Statistics by Course

SELECT 
    c.coursename,
    COUNT(e.examid) AS TotalExams,
    AVG(e.grade) AS AverageGrade,
    MAX(e.grade) AS HighestGrade,
    MIN(e.grade) AS LowestGrade
FROM exam e
JOIN course c ON e.courseid = c.courseid
GROUP BY c.coursename;

Get Student Exam Performance

SELECT 
    s.studentname,
    COUNT(e.examid) AS ExamsTaken,
    AVG(e.grade) AS AverageGrade,
    SUM(CASE WHEN e.grade >= 60 THEN 1 ELSE 0 END) AS PassedExams
FROM student s
LEFT JOIN exam e ON s.studentid = e.studentid
GROUP BY s.studentid, s.studentname;

πŸ‘¨β€πŸ’» Author

CrossITI Team


**⭐ Star this repository if you found it helpful!** Made with ❀️ using Microsoft SQL Server