Repository navigation
Expand file tree
/
Copy pathsetup.sql
More file actions
54 lines (47 loc) · 2.01 KB
/
Copy pathsetup.sql
File metadata and controls
54 lines (47 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- ============================================
-- Student Result Management System
-- MySQL Setup Script
-- Run this FIRST before launching the app
-- ============================================
CREATE DATABASE IF NOT EXISTS student_result_db;
USE student_result_db;
-- Students table
CREATE TABLE IF NOT EXISTS students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
roll_number VARCHAR(20) NOT NULL UNIQUE,
email VARCHAR(100),
branch VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Subjects table
CREATE TABLE IF NOT EXISTS subjects (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code VARCHAR(20) NOT NULL UNIQUE,
max_marks INT NOT NULL DEFAULT 100
);
-- Results table
CREATE TABLE IF NOT EXISTS results (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
subject_id INT NOT NULL,
marks_obtained INT NOT NULL,
UNIQUE KEY unique_result (student_id, subject_id),
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE,
FOREIGN KEY (subject_id) REFERENCES subjects(id) ON DELETE CASCADE
);
-- ── Sample Data ──────────────────────────────────────────────
INSERT INTO students (name, roll_number, email, branch) VALUES
('Rishi Sharma', 'CSE2401', '[email protected]', 'CSE'),
('Aryan Mehta', 'CSE2402', '[email protected]', 'CSE'),
('Priya Patel', 'CSE2403', '[email protected]', 'CSE');
INSERT INTO subjects (name, code, max_marks) VALUES
('Data Structures', 'CS101', 100),
('Object Oriented Prog', 'CS102', 100),
('Database Management', 'CS103', 100),
('Operating Systems', 'CS104', 100);
INSERT INTO results (student_id, subject_id, marks_obtained) VALUES
(1, 1, 88), (1, 2, 92), (1, 3, 85), (1, 4, 79),
(2, 1, 72), (2, 2, 68), (2, 3, 55), (2, 4, 60),
(3, 1, 45), (3, 2, 38), (3, 3, 50), (3, 4, 42);