Files
prog-solomov/works/kyrsach/avtoshkola-db.sql
T

64 lines
2.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Соломов Богдан
CREATE TABLE employees (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
full_name TEXT NOT NULL,
login TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
role TEXT NOT NULL
);
CREATE TABLE groups (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
group_name TEXT NOT NULL UNIQUE,
category TEXT NOT NULL,
price NUMERIC(10, 2) NOT NULL
);
CREATE TABLE students (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
full_name TEXT NOT NULL,
phone TEXT NOT NULL,
group_id INT NOT NULL REFERENCES groups(id),
is_paid BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE cars (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
model TEXT NOT NULL,
plate_number TEXT NOT NULL UNIQUE,
instructor_id INT NOT NULL REFERENCES employees(id)
);
CREATE TABLE lessons (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
student_id INT NOT NULL REFERENCES students(id),
car_id INT NOT NULL REFERENCES cars(id),
lesson_time TIMESTAMPTZ NOT NULL,
status TEXT NOT NULL
);
INSERT INTO employees (full_name, login, password, role) VALUES
('Соломов Богдан Егорович', 'admin', '1234', 'admin'),
('Пуховой Алексей Викторович', 'petrov', '1234', 'instructor'),
('Николаев Денис Николаевич', 'smirnov', '1234', 'instructor');
INSERT INTO groups (group_name, category, price) VALUES
('Б-101', 'B', 38000.00),
('Б-102', 'B', 38000.00),
('А-201', 'A', 22000.00);
INSERT INTO students (full_name, phone, group_id, is_paid) VALUES
('Смирнов Игорь Дмитриевич', '+79112345671', 1, TRUE),
('Самойлов Илья Игоревич', '+79112345672', 1, TRUE),
('Волков Никита Андреевич', '+79112345673', 1, FALSE),
('Крутой Никита Владимирович', '+79112345674', 2, TRUE);
INSERT INTO cars (model, plate_number, instructor_id) VALUES
('Lada Priora', 'А123ВС178', 2),
('Hyundai Solaris', 'К456МН178', 3);
INSERT INTO lessons (student_id, car_id, lesson_time, status) VALUES
(1, 1, '2026-11-10 10:00:00+03', 'Проведено'),
(2, 2, '2026-11-12 14:00:00+03', 'Проведено'),
(3, 1, '2026-11-29 12:00:00+03', 'Запланировано');