SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create schema Project create table Project.Stores ( store_id integer PRIMARY KEY, store_name varchar(200) NOT NULL UNIQUE, specialization varchar(200) ) create table Project.Store_warehouses ( warehouse_id integer PRIMARY KEY, store_id integer NOT NULL, address varchar(200) NOT NULL, capacity integer NOT NULL, FOREIGN KEY (store_id) REFERENCES Project.Stores ) create table Project.Product_information ( product_info_id integer PRIMARY KEY, product_name varchar(200) NOT NULL, size integer CHECK (size >= 0), production_date date CHECK (production_date <= best_before_date OR best_before_date IS NULL), best_before_date date, product_type varchar(200), producing_country varchar(200) ) create table Project.Products ( product_id integer PRIMARY KEY, product_info_id integer NOT NULL, warehouse_id integer NOT NULL, quantity integer CHECK (quantity >= 0), cost integer CHECK (cost >= 0), FOREIGN KEY (product_info_id) REFERENCES Project.Product_information, FOREIGN KEY (warehouse_id) REFERENCES Project.Store_warehouses ); /* Store table insertions start */ INSERT INTO Project.Stores VALUES (1001, 'Магнит', 'Продукты'), (1002, 'Пятёрочка', 'Продукты'), (1003, 'Вкусвилл', 'Продукты'), (1004, 'Мираторг', 'Продукты'); INSERT INTO Project.Stores VALUES (2001, 'Спортмастер', 'Спорттовары'); INSERT INTO Project.Stores VALUES (3001, 'Ситилинк', 'Электроника'), (3002, 'Мвидео', 'Электроника'), (3003, 'DNS', 'Электроника'); INSERT INTO Project.Stores VALUES (4001, 'Ольга', 'Аптека'), (4002, 'Татьяна', 'Аптека'); /* Store table insertions end */ /* Store_warehouses insertions start */ INSERT INTO Project.Store_warehouses VALUES (10010001, 1001, 'Ленина, 1', 10000), (10010002, 1001, 'Пушкина, 12', 10000); /* магнит */ INSERT INTO Project.Store_warehouses VALUES (10020001, 1002, 'Андреева, 2', 250); /* пятёрочка */ INSERT INTO Project.Store_warehouses VALUES (10030001, 1003, 'Первомайская, 32', 2000), (10030002, 1003, 'Второмайская, 31', 3000); /* вкусвилл */ INSERT INTO Project.Store_warehouses VALUES (10040001, 1004, 'Цвиллинга, 15', 2500); /* мираторг */ INSERT INTO Project.Store_warehouses VALUES (20010001, 2001, 'Петрова, 22', 30000); /* спортмастер */ INSERT INTO Project.Store_warehouses VALUES (30010001, 3001, 'Васина, 11', 2534); /* ситилинк */ INSERT INTO Project.Store_warehouses VALUES (30020001, 3002, 'Лёшина, 250', 2443); /* мвидео */ INSERT INTO Project.Store_warehouses VALUES (30030001, 3003, 'Первомайская, 55', 5544); /* DNS */ INSERT INTO Project.Store_warehouses VALUES (40010001, 4001, 'Халилова, 33', 123); /* ольга */ INSERT INTO Project.Store_warehouses VALUES (40020001, 4002, 'Салавата Юлаева, 44', 321); /* татьяна */ /* Store_warehouses insertions end */ /* Product_information insertions start */ INSERT INTO Project.Product_information VALUES (1, 'Вода "Святой источник"', 1, '2022-02-17', '2022-03-17', 'Продовольственный', 'Россия'), (2, 'Хлеб "Столичный"', 1, '2022-02-15', '2022-02-22', 'Продовольственный', 'Россия'), (3, 'Велосипед "Forward"', 30, '2015-05-02', NULL, 'Велосипеды', 'Украина'), (4, 'Ноутбук ACER SWIFT 3', 2, '2020-05-12', NULL, 'Ноутбуки', 'США'), (5, 'IPhone 13 PRO MAX', 1, '2021-10-10', NULL, 'Смартфоны', 'США'), (6, 'Сок RICH вишневый 1л', 1, '2022-02-17', '2023-02-17', 'Продовольственный', 'Россия'), (7, 'Чай TESS 100 пакетиков', 1, '2022-02-17', '2023-02-17', 'Продовольственный', 'Россия'), (8, 'Паксил', 1, '2022-01-05', '2024-01-05', 'Антидепрессанты', 'Россия'), (9, 'Анальгин', 1, '2022-01-03', '2024-01-05', 'Таблетки', 'Россия'), (10, 'Футбольный мяч "Demix"', 1, '2021-11-04', NULL, 'Футбольные мячи', 'Россия'); /* Product_information insertions end */ /*Products insertions start */ INSERT INTO Project.Products VALUES (1, 1, 10010001, 100, 90), (2, 1, 10020001, 100, 80), (3, 2, 10020001, 10, 25), (4, 3, 20010001, 15, 15000), (5, 4, 30010001, 10, 100000), (6, 5, 30020001, 10, 150000), (7, 6, 10040001, 100, 150), (8, 8, 40010001, 10, 3000), (9, 9, 40020001, 10, 50), (10, 10, 20010001, 10, 300); /*Products insertions start */ UPDATE Project.Products SET cost = cost - 10 WHERE quantity >= 100; DELETE FROM Project.Products WHERE cost > 100000; UPDATE Project.Product_information SET product_type = 'Продовольственные' WHERE product_type = 'Продовольственный'; INSERT INTO Project.Product_information VALUES (100, 'Сахар "Уральский"', 1, '2022-02-12', '2023-02-12', 'Продовольственные', 'Russia'); UPDATE Project.Store_warehouses SET capacity = 300 WHERE capacity < 300; INSERT INTO Project.Stores VALUES (5001, 'Андрюха', 'Косметика'); INSERT INTO Project.Store_warehouses VALUES (50010001, 5001, 'Халилова, 10', 5000); SELECT * FROM Project.Stores; SELECT * FROM Project.Store_warehouses; SELECT * FROM Project.Product_information; SELECT * FROM Project.Products;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear