Files
sql_advanced/lab2-10/task2.sql
T
Vitalii Litvinchuk 6deed0469a first commit
2026-05-04 23:15:09 +03:00

65 lines
1.3 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 DATABASE EventsDB;
USE EventsDB;
CREATE TABLE Messages (
id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(100),
created_at DATETIME
);
SET GLOBAL event_scheduler = ON;
#1.1 Створіть одноразову подію (слайд 33)
CREATE EVENT IF NOT EXISTS test_event_02
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 20 second
ON COMPLETION PRESERVE
DO
INSERT INTO
Messages(message,created_at)
VALUES('Test MySQL Event 2', DATE_FORMAT(
CONVERT_TZ(
UTC_TIMESTAMP(),
'+00:00',
'Europe/Kyiv'
),
'%Y-%m-%d %H:%i:%s'
));
drop event test_event_02;
ALTER EVENT test_event_02
ON SCHEDULE AT NOW()
ENABLE;
SHOW EVENTS;
# 1.2 Переконайтеся у її працездатності
select * from Messages;
# 2.1 Створіть повторювану подію (слайд 34)
CREATE EVENT test_event_03
ON SCHEDULE EVERY 1 MINUTE
STARTS CURRENT_TIMESTAMP
ENDS CURRENT_TIMESTAMP + INTERVAL 5 MINUTE
DO
INSERT INTO Messages(message,created_at)
VALUES('Test MySQL recurring Event', DATE_FORMAT(
CONVERT_TZ(
UTC_TIMESTAMP(),
'+00:00',
'Europe/Kyiv'
),
'%Y-%m-%d %H:%i:%s'
));
drop event test_event_03;
SHOW EVENTS;
# 2.2 Переконайтеся у її працездатності
select * from Messages;
set global time_zone = 'Europe/Kyiv';