forked from Open-Bootcamp/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsesion2-dml.sql
87 lines (46 loc) · 2.24 KB
/
sesion2-dml.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Sentencias DML: Data Manipulation Language
CRUD:
Create (INSERT INTO)
Read (SELECT FROM),
Update (UPDATE SET)
Delete (DELETE FROM)
*/
-- 1. Consultas o recuperación de datos
SELECT * FROM employees;
SELECT id FROM employees;
SELECT id, email FROM employees;
SELECT email, id FROM employees;
SELECT id, email, salary FROM employees;
-- Filtrar filas
SELECT * FROM employees WHERE id = 1;
SELECT * FROM employees WHERE name = 'Employee1';
SELECT * FROM employees WHERE married = 'true';
SELECT * FROM employees WHERE married = TRUE;
SELECT * FROM employees WHERE birth_date = '1990-12-25';
SELECT * FROM employees WHERE married = TRUE AND salary > 10000;
-- 2. Inserción de datos
INSERT INTO employees(name, email) VALUES ('Juan', '[email protected]');
INSERT INTO employees(name, email, married, genre, salary)
VALUES ('antonio4', '[email protected]', TRUE, 'M', 23566.43);
INSERT INTO employees(name, email, married, genre, salary, birth_date, start_at)
VALUES ('francisco', '[email protected]', TRUE, 'M', 23566.43, '1987-5-29', '10:00:00');
INSERT INTO employees(name, email, married, genre, salary, birth_date, start_at)
VALUES ('Rosa', '[email protected]', FALSE, 'F', 34543.43, '1990-5-29', '10:00:00');
INSERT INTO employees(name, email, married, genre, salary, birth_date, start_at)
VALUES ('Alberto', '[email protected]', FALSE, 'M', 32421.43, '1988-5-29', '10:00:00');
INSERT INTO employees
VALUES (9, TRUE, 'francisco3', '[email protected]', 'M', 23566.43, '1987-5-29', '10:00:00');
-- 3. Actualizar o editar
UPDATE employees SET birth_date = '2000-03-12';
UPDATE employees SET birth_date = '2000-03-12' WHERE id = 5;
UPDATE employees SET salary = 45000 WHERE email = '[email protected]';
UPDATE employees SET genre = 'M', start_at = '08:30:00' WHERE email = '[email protected]';
UPDATE employees SET genre = 'M', start_at = '08:30:00' WHERE email = '[email protected]';
UPDATE employees SET genre = 'M', start_at = '08:30:00' WHERE email = '[email protected]' RETURNING *;
UPDATE employees SET genre = NULL WHERE id = 14;
-- 4. Borrar
SELECT * FROM employees;
DELETE FROM employees;
DELETE FROM employees WHERE married = TRUE;
DELETE FROM employees WHERE salary < 33000;
DELETE FROM employees WHERE salary IS NULL;