Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.4 KB

2. Sentencias DML.md

File metadata and controls

56 lines (37 loc) · 1.4 KB

Sentencias DML

Data Manipulation Language

Operaciones CRUD:

  • ==C==: Create --> INSERT INTO
  • ==R==: Retrieve o Read --> SELECT FROM
  • ==U==: Update --> UPDATE
  • ==D==: Delete --> DELETE FROM

1. Recuperar datos (SELECT)

Recuperar todos los empleados:

SELECT * FROM employees;

Recuperar con condición :

SELECT * FROM employees WHERE married = TRUE AND salary > 1000 ;

2. Insertar nuevos datos (INSERT)

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');

3. Actualizar datos (UPDATE)

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.

4. Borrar datos (DELETE)

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;