PIbd-21_Kudyaeva_V.A._Sessi.../2labOTP.sql

49 lines
1.3 KiB
SQL

-- Таблица Teacher
CREATE TABLE Teacher (
ID SERIAL PRIMARY KEY,
Surname VARCHAR(255) NOT NULL,
Name VARCHAR(255) NOT NULL,
MiddleName VARCHAR(255)
);
-- Таблица Group
CREATE TABLE "Group" (
ID SERIAL PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Type INT NOT NULL
);
-- Таблица Student
CREATE TABLE Student (
ID SERIAL PRIMARY KEY,
Surname VARCHAR(255) NOT NULL,
Name VARCHAR(255) NOT NULL,
MiddleName VARCHAR(255),
GroupID INT NOT NULL REFERENCES "Group"(ID) ON DELETE CASCADE
);
-- Таблица Discipline
CREATE TABLE Discipline (
ID SERIAL PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Description TEXT NOT NULL,
Courses INT NOT NULL,
TeacherId INT NOT NULL REFERENCES Teacher(ID) ON DELETE CASCADE
);
-- Таблица Statement
CREATE TABLE Statement (
ID SERIAL PRIMARY KEY,
TeacherId INT NOT NULL REFERENCES Teacher(ID) ON DELETE CASCADE,
DisciplineId INT NOT NULL REFERENCES Discipline(ID) ON DELETE CASCADE,
Date DATE NOT NULL
);
-- Таблица StatementStudent (многие ко многим)
CREATE TABLE StatementStudent (
ID SERIAL PRIMARY KEY,
StudentId INT NOT NULL REFERENCES Student(ID) ON DELETE CASCADE,
StatementId INT NOT NULL REFERENCES Statement(ID) ON DELETE CASCADE,
Mark INT NOT NULL
);