Skip to content

Commit c5982f5

Browse files
committed
Added new assignments
[Databases] ~/R2S2/
1 parent 05e801b commit c5982f5

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

R2S2/Bazy Danych (L)/.idea/sqldialects.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Zadanie 02
2+
3+
-- Sprawdzenie aktualnego statusu sprawdzania kluczy obcych (opcjonalnie)
4+
SELECT @@FOREIGN_KEY_CHECKS;
5+
6+
-- Wyłączenie sprawdzania kluczy obcych
7+
SET FOREIGN_KEY_CHECKS = 0;
8+
9+
-- Kasowanie danych z tabel
10+
DELETE FROM customer;
11+
DELETE FROM dept;
12+
DELETE FROM emp;
13+
DELETE FROM inventory;
14+
DELETE FROM item;
15+
DELETE FROM ord;
16+
DELETE FROM price_category;
17+
DELETE FROM product;
18+
DELETE FROM region;
19+
DELETE FROM title;
20+
DELETE FROM warehouse;
21+
22+
-- Włączenie sprawdzania kluczy obcych
23+
SET FOREIGN_KEY_CHECKS = 1;
24+
25+
-- Sprawdzenie czy ponownie włączone (opcjonalnie)
26+
SELECT @@FOREIGN_KEY_CHECKS;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- Zadanie 03
2+
3+
4+
-- region
5+
INSERT INTO region (id, name) VALUES
6+
(1, 'North America'),
7+
(2, 'Europe'),
8+
(3, 'Asia'),
9+
(4, 'South America'),
10+
(5, 'Australia');
11+
12+
13+
-- dept
14+
INSERT INTO dept (id, name, region_id) VALUES
15+
(1, 'Sales', 1),
16+
(2, 'Marketing', 1),
17+
(3, 'Engineering', 2),
18+
(4, 'Support', 3),
19+
(5, 'Finance', 1),
20+
(6, 'IT', 2),
21+
(7, 'Legal', 1),
22+
(8, 'Operations', 4),
23+
(9, 'Research', 2),
24+
(10, 'Logistics', 4),
25+
(11, 'HR', 3),
26+
(12, 'Customer Success', 1),
27+
(13, 'Procurement', 3),
28+
(14, 'Analytics', 2),
29+
(15, 'QA', 2);
30+
31+
32+
-- emp
33+
-- Styl 1: pełna lista kolumn
34+
INSERT INTO emp (id, last_name, first_name, userid, start_date, comments, manager_id, title, dept_id, salary, commission_pct) VALUES
35+
(1, 'Smith', 'John', 'jsmith', '2020-01-15', NULL, NULL, 'CEO', 1, 150000.00, NULL),
36+
(2, 'Taylor', 'Alice', 'ataylor', '2021-03-22', NULL, 1, 'CTO', 1, 130000.00, NULL),
37+
(3, 'Brown', 'Charlie', 'cbrown', '2022-07-10', NULL, 2, 'Manager', 2, 95000.00, NULL),
38+
(4, 'White', 'Emily', 'ewhite', '2023-01-05', NULL, 3, 'Engineer', 1, 85000.00, 0.05),
39+
(5, 'Green', 'Daniel', 'dgreen', '2021-06-19', NULL, 3, 'Engineer', 1, 87000.00, 0.07),
40+
(6, 'Black', 'Sophia', 'sblack', '2020-11-03', NULL, 3, 'Marketing Specialist', 2, 65000.00, NULL),
41+
(7, 'King', 'Oliver', 'oking', '2023-04-28', NULL, 3, 'Intern', 1, 20000.00, NULL),
42+
(8, 'Wright', 'Mia', 'mwright', '2021-09-15', NULL, 2, 'HR Specialist', 4, 60000.00, NULL),
43+
(9, 'Scott', 'Jacob', 'jscott', '2022-05-20', NULL, 2, 'Engineer', 1, 88000.00, NULL),
44+
(10, 'Bell', 'Emma', 'ebell', '2019-08-13', NULL, 3, 'Sales Representative', 3, 62000.00, 0.1);
45+
46+
-- Styl 2: insert bez nazw kolumn (kolejność musi odpowiadać tabeli!)
47+
INSERT INTO emp VALUES
48+
(11, 'Adams', 'Grace', 'gadams', '2020-02-11', NULL, 3, 'Engineer', 1, 83000.00, NULL),
49+
(12, 'Baker', 'Henry', 'hbaker', '2021-10-01', NULL, 3, 'Engineer', 1, 81000.00, 0.05),
50+
(13, 'Carter', 'Liam', 'lcarter', '2020-12-20', NULL, 3, 'Engineer', 1, 80000.00, NULL),
51+
(14, 'Davis', 'Ella', 'edavis', '2022-06-08', NULL, 3, 'Engineer', 1, 79000.00, NULL),
52+
(15, 'Evans', 'Noah', 'nevans', '2023-02-15', NULL, 3, 'Engineer', 1, 77000.00, NULL),
53+
(16, 'Foster', 'Ava', 'afoster', '2022-09-25', NULL, 3, 'Marketing Specialist', 2, 63000.00, NULL),
54+
(17, 'Graham', 'Mason', 'mgraham', '2020-10-30', NULL, 3, 'Sales Representative', 3, 61000.00, 0.12),
55+
(18, 'Hall', 'Isabella', 'ihall', '2021-04-18', NULL, 3, 'Sales Representative', 3, 60000.00, 0.09),
56+
(19, 'Irwin', 'James', 'jirwin', '2020-07-07', NULL, 3, 'Engineer', 1, 75000.00, NULL),
57+
(20, 'Jones', 'Lily', 'ljones', '2023-03-12', NULL, 3, 'Intern', 1, 18000.00, NULL);
58+
59+
60+
-- customer
61+
INSERT INTO customer (id, name, region_id) VALUES
62+
(1, 'Beisbol Si!', 4),
63+
(2, 'Sweet Rock Sports', 1),
64+
(3, 'Sporta Russia', 3),
65+
(4, 'Womansport', 2),
66+
(5, 'Hamada Sport', 3);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- Zadanie 04
2+
3+
-- Aktualizacja nazwisk na wielkie litery
4+
UPDATE emp
5+
SET last_name = UPPER(last_name);
6+
7+
-- Imię: pierwsza litera wielka, reszta małe (capitalize)
8+
UPDATE emp
9+
SET first_name = CONCAT(UPPER(LEFT(first_name, 1)), LOWER(SUBSTRING(first_name, 2)));
10+
11+
-- Podwyżka 100 zł
12+
UPDATE emp
13+
SET salary = salary + 100;
14+
15+
-- Zaokrąglanie daty do 1. dnia miesiąca (jeśli dzień > 15, to do kolejnego miesiąca)
16+
UPDATE emp
17+
SET start_date = CASE
18+
WHEN DAY(start_date) > 15
19+
THEN DATE_FORMAT(DATE_ADD(LAST_DAY(start_date), INTERVAL 1 DAY), '%Y-%m-01')
20+
ELSE DATE_FORMAT(start_date, '%Y-%m-01')
21+
END;
22+
23+
-- Zastąpienie NULL znakiem zapytania
24+
UPDATE emp
25+
SET
26+
first_name = IFNULL(first_name, '?'),
27+
last_name = IFNULL(last_name, '?'),
28+
userid = IFNULL(userid, '?'),
29+
comments = IFNULL(comments, '?');
30+
31+
-- Uzupełnienie kolumny comments zgodnie z formatem
32+
UPDATE emp e
33+
JOIN dept d ON e.dept_id = d.id
34+
JOIN region r ON d.region_id = r.id
35+
SET e.comments = CONCAT(
36+
e.first_name, ' ', e.last_name, ' : ',
37+
UPPER(LEFT(e.first_name, 1)), '.', UPPER(LEFT(e.last_name, 1)), '. : ',
38+
FORMAT(e.salary, 2), ' zł : ',
39+
DATE_FORMAT(e.start_date, '%d-%m-%Y'), ' : ',
40+
r.name, ' : ',
41+
d.name
42+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Zadanie 05
2+
3+
-- Wyłączenie sprawdzania kluczy obcych (jeśli potrzebne)
4+
SET FOREIGN_KEY_CHECKS = 0;
5+
6+
-- Usunięcie pracowników z działów 3 i 5
7+
DELETE FROM emp
8+
WHERE dept_id IN (3, 5);
9+
10+
-- Usunięcie działów 3 i 5
11+
DELETE FROM dept
12+
WHERE id IN (3, 5);
13+
14+
-- Ponowne włączenie sprawdzania kluczy obcych
15+
SET FOREIGN_KEY_CHECKS = 1;

0 commit comments

Comments
 (0)