Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions 80 lesson11/task1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#Задание1

use shop;
DROP TABLE IF exists logs;
CREATE TABLE logs (
#id SERIAL PRIMARY KEY,
id_PK INT UNSIGNED,
table_name VARCHAR(25),
field_name VARCHAR(25),
created_at DATETIME DEFAULT NOW()
)engine=archive;

drop trigger if exists tr_logs_write_users;
drop trigger if exists tr_logs_write_catalogs;
drop trigger if exists tr_logs_write_products;
delimiter //
CREATE TRIGGER tr_logs_write_users After insert ON users
FOR EACH ROW BEGIN
INSERT INTO logs
(id_PK, table_name, field_name)
VALUES
(NEW.id, 'users', NEW.name);
END//

CREATE TRIGGER tr_logs_write_catalogs After insert ON catalogs
FOR EACH ROW BEGIN
INSERT INTO logs
(id_PK, table_name, field_name)
VALUES
(NEW.id, 'catalogs', NEW.name);
END//

CREATE TRIGGER tr_logs_write_products After insert ON products
FOR EACH ROW BEGIN
INSERT INTO logs
(id_PK, table_name, field_name)
VALUES
(NEW.id, 'products', NEW.name);
END//

delimiter ;

### Test

INSERT INTO users (name, birthday_at) VALUES
('Сергей', '1995-10-15');

INSERT INTO products
(name, description, price, catalog_id)
VALUES
('Intel Core i7-8100', 'Процессор для настольных персональных компьютеров, основанных на платформе Intel.', 8890.00, 1);

INSERT INTO catalogs VALUES
(NULL, 'Блоки питания');




#Задание2

use shop;

drop procedure if exists dorepeat;
delimiter //

CREATE PROCEDURE dorepeat()
BEGIN
SET @x = 0;
set @p1 = 1000000;
REPEAT
SET @x = @x + 1;
INSERT INTO users (name, birthday_at) VALUES
('Геннадий', '1990-10-05');
UNTIL @x > @p1 END REPEAT;
END
//

DELIMITER ;

CALL dorepeat();
79 changes: 79 additions & 0 deletions 79 lesson11/task2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
################################
#Задание1
sadd 192.168.0.1 user1
sadd 192.168.0.1 user2
sadd 192.168.0.2 user3
sadd 192.168.0.3 user4
sass 192.168.0.1 user4
sadd 192.168.0.1 user4
sadd 192.168.0.2 user2
smembers 192.168.0.1


################################
#Задание2
select 2
set user1 user1@mail.ru
set user2 user2@mail.ru
set user3 user3@mail.ru
set user4 user4@mail.ru
set user5 user5@mail.ru

#Получаем email пользователя
get user4

#Получаем hash таблицу
hset users:1 name "name1"
hset users:1 name "n1@n.ru"
hset users:2 name "name2"
hset users:2 name "n2@n.ru"
hset users:3 name "name3"
hset users:3 name "n3@n.ru"

hvals users:1
hkeys users:1


################################
#Задание3
db.shop.insert(
{
"id":1,
"name":"Intel Core i3-8100",
"description":"Процессор для настольных персональных компьютеров, основанных на платформе Intel.",
"price":7890,
"catalog_id":1,
"creates_at":"2019-11-24 10:00:00",
"update_at":"2019-11-24 10:00:00"
})
db.shop.insert(
{
"id":2,
"name":"Intel Core i5-7400",
"description":"Процессор для настольных персональных компьютеров, основанных на платформе Intel.",
"price":12700,
"catalog_id":1,
"creates_at":"2019-11-24 10:00:00",
"update_at":"2019-11-24 10:00:00"
})
db.shop.insert(
{
"id":3,
"name":"Gigabyte H310M S2H",
"description":"Материнская плата Gigabyte H310M S2H, H310, Socket 1151-V2, DDR4, mATX",
"price":4790,
"catalog_id":2,
"creates_at":"2019-11-24 10:00:00",
"update_at":"2019-11-24 10:00:00"
})

db.shop.insert(
{
"id":1,
"name":"Процессоры"
})
db.shop.insert(
{
"id":2,
"name":"Материнские платы"
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.