
CREATE DATABASE IF NOT EXISTS db_cbt_ultimate;
USE db_cbt_ultimate;

CREATE TABLE kelas (
 id INT AUTO_INCREMENT PRIMARY KEY,
 nama VARCHAR(20)
);

CREATE TABLE siswa (
 id INT AUTO_INCREMENT PRIMARY KEY,
 user_id INT,
 kelas_id INT,
 nama VARCHAR(100),
 nis VARCHAR(20)
);

CREATE TABLE mapel (
 id INT AUTO_INCREMENT PRIMARY KEY,
 nama VARCHAR(50)
);

CREATE TABLE soal (
 id INT AUTO_INCREMENT PRIMARY KEY,
 mapel_id INT,
 pertanyaan TEXT,
 a VARCHAR(100),
 b VARCHAR(100),
 c VARCHAR(100),
 d VARCHAR(100),
 jawaban CHAR(1),
 bobot INT
);

CREATE TABLE ujian (
 id INT AUTO_INCREMENT PRIMARY KEY,
 mapel_id INT,
 kelas_id INT,
 durasi INT,
 mulai DATETIME,
 selesai DATETIME
);

CREATE TABLE jawaban (
 id INT AUTO_INCREMENT PRIMARY KEY,
 ujian_id INT,
 soal_id INT,
 siswa_id INT,
 jawaban CHAR(1)
);

CREATE TABLE nilai (
 id INT AUTO_INCREMENT PRIMARY KEY,
 ujian_id INT,
 siswa_id INT,
 nilai INT
);
