Загрузка данных


-- очистка таблиц (если нужно перезаполнить)
truncate table orders cascade;
truncate table book_writer cascade;
truncate table contract cascade;
truncate table book cascade;
truncate table customer cascade;
truncate table writer cascade;

-- 1. писатели
insert into writer (passport_no, last_name, first_name, middle_name, address, phone) values ('1234-567890', 'иванов', 'иван', 'иванович', 'г. москва, ул. ленина, д. 1, кв. 5', '+79001234567');
insert into writer (passport_no, last_name, first_name, middle_name, address, phone) values ('2345-678901', 'петров', 'пётр', 'петрович', 'г. москва, ул. пушкина, д. 2, кв. 10', '+79007654321');
insert into writer (passport_no, last_name, first_name, middle_name, address, phone) values ('3456-789012', 'сидоров', 'сергей', 'сергеевич', 'г. санкт-петербург, невский пр., д. 5, кв. 12', '+78123456789');
insert into writer (passport_no, last_name, first_name, middle_name, address, phone) values ('4567-890123', 'козлова', 'елена', 'ивановна', 'г. казань, ул. баумана, д. 3, кв. 8', '+78431234567');

-- 2. контракты
insert into contract (writer_passport, sign_date, term_years, restaurant_flag, restaurant_date) values ('1234-567890', '2025-01-01', 3, false, null);
insert into contract (writer_passport, sign_date, term_years, restaurant_flag, restaurant_date) values ('2345-678901', '2025-02-01', 2, true, '2025-02-01');
insert into contract (writer_passport, sign_date, term_years, restaurant_flag, restaurant_date) values ('3456-789012', '2025-03-01', 1, false, null);
insert into contract (writer_passport, sign_date, term_years, restaurant_flag, restaurant_date) values ('4567-890123', '2025-01-15', 2, false, null);

-- 3. книги
insert into book (book_code, title, publisher, release_date, cost_price, sale_price, royalty_total) values ('b001', 'война и мир', 'издательство "наука"', '2025-03-10', 500.00, 1200.00, 300.00);
insert into book (book_code, title, publisher, release_date, cost_price, sale_price, royalty_total) values ('b002', 'анна каренина', 'издательство "художественная литература"', '2025-04-05', 400.00, 1100.00, 250.00);
insert into book (book_code, title, publisher, release_date, cost_price, sale_price, royalty_total) values ('b003', 'преступление и наказание', 'издательство "эксмо"', '2025-05-15', 350.00, 950.00, 200.00);
insert into book (book_code, title, publisher, release_date, cost_price, sale_price, royalty_total) values ('b004', 'мастер и маргарита', 'издательство "аст"', '2025-06-20', 450.00, 1300.00, 280.00);
insert into book (book_code, title, publisher, release_date, cost_price, sale_price, royalty_total) values ('b005', 'тихий дон', 'издательство "дрофа"', '2025-07-01', 380.00, 1000.00, 220.00);

-- 4. связь писатель-книга
insert into book_writer (book_code, writer_passport) values ('b001', '1234-567890');
insert into book_writer (book_code, writer_passport) values ('b001', '2345-678901');
insert into book_writer (book_code, writer_passport) values ('b002', '1234-567890');
insert into book_writer (book_code, writer_passport) values ('b003', '2345-678901');
insert into book_writer (book_code, writer_passport) values ('b004', '3456-789012');
insert into book_writer (book_code, writer_passport) values ('b005', '4567-890123');

-- 5. заказчики
insert into customer (name, address, phone, contact_person) values ('ооо "книжный мир"', 'г. москва, ул. тверская, д. 15', '+74951234567', 'сидорова анна алексеевна');
insert into customer (name, address, phone, contact_person) values ('гбук "библиотека №1"', 'г. санкт-петербург, невский пр., д. 10', '+78121234567', 'кузнецов борис борисович');
insert into customer (name, address, phone, contact_person) values ('ип иванова е.м.', 'г. казань, ул. кремлевская, д. 8', '+78431234568', 'иванова елена михайловна');
insert into customer (name, address, phone, contact_person) values ('ооо "книги-маркет"', 'г. новосибирск, пр. красный, д. 20', '+73831234567', 'петров сергей николаевич');
insert into customer (name, address, phone, contact_person) values ('мбук "дом книги"', 'г. екатеринбург, ул. ленина, д. 5', '+73431234567', 'смирнов александр петрович');

-- 6. заказы
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b001', 1, '2025-03-12', '2025-03-25', 100);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b001', 2, '2025-03-15', '2025-03-28', 50);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b002', 1, '2025-04-08', '2025-04-20', 200);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b003', 3, '2025-05-18', '2025-05-30', 75);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b003', 4, '2025-05-20', '2025-06-01', 120);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b004', 2, '2025-06-22', null, 30);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b004', 5, '2025-06-25', null, 45);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b005', 1, '2025-07-05', '2025-07-15', 60);
insert into orders (book_code, customer_id, order_date, execute_date, quantity) values ('b005', 3, '2025-07-08', null, 80);