Add dml.sql and fix ddl.sql
This commit is contained in:
@@ -8,7 +8,7 @@ create table akalyanov.users (
|
|||||||
is_active boolean,
|
is_active boolean,
|
||||||
created_at timestamp not null
|
created_at timestamp not null
|
||||||
);
|
);
|
||||||
-- Таблица товаров
|
-- Таблица продуктов
|
||||||
create table akalyanov.products (
|
create table akalyanov.products (
|
||||||
id int primary key,
|
id int primary key,
|
||||||
name varchar(100) not null,
|
name varchar(100) not null,
|
||||||
@@ -20,7 +20,7 @@ create table akalyanov.products (
|
|||||||
create table akalyanov.orders (
|
create table akalyanov.orders (
|
||||||
id int primary key,
|
id int primary key,
|
||||||
user_id int,
|
user_id int,
|
||||||
order_date date not null,
|
order_date timestamptz not null,
|
||||||
status varchar(20),
|
status varchar(20),
|
||||||
foreign key (user_id) references akalyanov.users(id)
|
foreign key (user_id) references akalyanov.users(id)
|
||||||
);
|
);
|
||||||
@@ -30,5 +30,7 @@ create table akalyanov.order_items (
|
|||||||
product_id int,
|
product_id int,
|
||||||
quantity smallint not null,
|
quantity smallint not null,
|
||||||
price_at_purchase decimal(10,2) not null,
|
price_at_purchase decimal(10,2) not null,
|
||||||
primary key (order_id, product_id)
|
primary key (order_id, product_id),
|
||||||
|
foreign key (order_id) references akalyanov.orders(id),
|
||||||
|
foreign key (product_id) references akalyanov.products(id)
|
||||||
);
|
);
|
||||||
46
SQL/dml.sql
Normal file
46
SQL/dml.sql
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
-- Добавление пользователей в таблицу users
|
||||||
|
insert into akalyanov.users (id, name, age, email, country, is_active, created_at) values
|
||||||
|
(1, 'Alice', 25, 'alice@example.com', 'US', true, '2024-01-10 10:00:00'),
|
||||||
|
(2, 'Bob', 30, 'bob@example.com', 'UK', true, '2024-02-05 09:30:00'),
|
||||||
|
(3, 'Carol', 27, 'carol@example.com', 'US', false, '2024-03-01 15:20:00'),
|
||||||
|
(4, 'Diana', 22, 'diana@GMAIL.com', 'US', true, '2024-01-12 08:15:00'),
|
||||||
|
(5, 'Evan', 35, 'EVAN@example.com', 'UK', true, '2024-01-18 19:40:00'),
|
||||||
|
(6, 'Farida', 29, 'farida@example.com', 'KZ', true, '2024-02-20 11:05:00'),
|
||||||
|
(7, 'George', 31, 'george+test@example.com', 'US', true, '2024-03-05 16:45:00'),
|
||||||
|
(8, 'Helen', 24, NULL, 'UK', false, '2024-03-06 08:20:00'),
|
||||||
|
(9, 'Ivan', 26, 'ivan@example.com', 'RU', true, '2024-01-11 14:30:00'),
|
||||||
|
(10, 'Julia', 28, 'julia@example.com', 'US', true, '2024-03-07 18:05:00');
|
||||||
|
|
||||||
|
-- Добавление товаров в таблицу products
|
||||||
|
insert into akalyanov.products (id, name, category, price, in_stock) values
|
||||||
|
(1, 'iPhone 15', 'Электроника', 80000, true),
|
||||||
|
(2, 'Kindle', 'Электроника', 15000, true),
|
||||||
|
(3, 'Кроссовки Nike', 'Одежда', 9000, true),
|
||||||
|
(4, 'Кроссовки NoName', 'Одежда', 3000, false),
|
||||||
|
(5, 'Наушники Pro', 'Электроника', 12000, true),
|
||||||
|
(6, 'Фитнес‑браслет', 'Гаджеты', 6000, true),
|
||||||
|
(7, 'Подарочная карта', 'Сервисы', 1000, true);
|
||||||
|
|
||||||
|
-- Добавление заказов в таблицу orders
|
||||||
|
insert into akalyanov.orders (id, user_id, order_date, status) values
|
||||||
|
(1, 1, '2025-01-10 12:00:00', 'paid'),
|
||||||
|
(2, 3, '2025-01-12 09:30:00', 'cancelled'),
|
||||||
|
(3, 1, '2025-01-15 18:20:00', 'paid'),
|
||||||
|
(4, 2, '2025-01-20 11:05:00', 'created'),
|
||||||
|
(5, 4, '2025-02-01 17:45:00', 'paid'),
|
||||||
|
(6, 5, '2025-02-10 10:10:00', 'refunded'),
|
||||||
|
(7, 7, '2025-03-01 09:00:00', 'paid'),
|
||||||
|
(8, 9, '2025-03-05 19:30:00', 'paid');
|
||||||
|
|
||||||
|
-- Добавление товаров в таблицу order_items
|
||||||
|
insert into akalyanov.order_items (order_id, product_id, quantity, price_at_purchase) values
|
||||||
|
(1, 1, 1, 78000),
|
||||||
|
(1, 3, 2, 8500),
|
||||||
|
(2, 2, 1, 14000),
|
||||||
|
(3, 5, 1, 11000),
|
||||||
|
(3, 7, 1, 1000),
|
||||||
|
(4, 2, 1, 15000),
|
||||||
|
(5, 6, 1, 6000),
|
||||||
|
(6, 1, 1, 82000),
|
||||||
|
(7, 3, 1, 9000),
|
||||||
|
(8, 4, 2, 2800);
|
||||||
Reference in New Issue
Block a user