Data Manipulation Language
Operaciones CRUD:
- ==C==: Create -->
INSERT INTO
- ==R==: Retrieve o Read -->
SELECT FROM
- ==U==: Update -->
UPDATE
- ==D==: Delete -->
DELETE FROM
Recuperar todos los empleados:
SELECT * FROM employees;
Recuperar con condición :
SELECT * FROM employees WHERE married = TRUE AND salary > 1000 ;
Insertar un nuevo empleado:
INSERT INTO employees (married, name, email, genre, salary, birth_date, start_at) VALUES (TRUE, 'Employee2', '[email protected]', 'M', 29567.23, '1990-12-25', '08:30:00');
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]';
//El primero no es muy recomendable ya que actualiza toda la columna a la fecha puesta. La idea es siempre que actualizamos filtrar para que lo haga en la fila adecuada, puede ser por un parametro unico como lo es id o email. SET (columna) = (ALGO) significa actualiza con el valor algo esta columna.
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;