Files
prog-solomov/works/kyrsach/avtoshkola-db.sql
T
2026-11-29 12:01:49 +03:00

65 lines
2.1 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 SERIAL PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
login VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(50) NOT NULL,
role VARCHAR(20) NOT NULL
);
CREATE TABLE groups (
id SERIAL PRIMARY KEY,
group_name VARCHAR(20) NOT NULL UNIQUE,
category VARCHAR(5) NOT NULL,
price INT NOT NULL
);
CREATE TABLE students (
id SERIAL PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
phone VARCHAR(20) NOT NULL,
group_id INT NOT NULL REFERENCES groups(id),
is_paid BOOLEAN DEFAULT FALSE
);
CREATE TABLE cars (
id SERIAL PRIMARY KEY,
model VARCHAR(50) NOT NULL,
plate_number VARCHAR(15) NOT NULL UNIQUE,
instructor_id INT NOT NULL REFERENCES employees(id)
);
CREATE TABLE lessons (
id SERIAL PRIMARY KEY,
student_id INT NOT NULL REFERENCES students(id),
car_id INT NOT NULL REFERENCES cars(id),
lesson_date DATE NOT NULL,
status VARCHAR(20) 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),
('Б-102', 'B', 38000),
('А-201', 'A', 22000);
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_date, status) VALUES
(1, 1, '2026-11-10', 'Проведено'),
(2, 2, '2026-11-12', 'Проведено'),
(3, 1, '2026-11-29', 'Запланировано');