Files
live-campus-mcs-p-2027.2/Semaine_07/Jour_02/SQL_transactions.sql
gauvainboiche 606e43e53f Semaine 7
2026-03-20 21:26:23 +01:00

38 lines
774 B
SQL

-- Création de "Transactions"
-- -- ACID : Atomique, Cohérence, Isolation, Durabilité
-- -- minimum deux requêtes, et si l'une échoue,
-- -- la BDD revient à l'état initial. Toutes passent sinon aucune
-- -- -- On veut transférer un employé vers un autre département
-- -- -- avec un nouveau job, et archiver son poste dans job_history
START transaction;
-- -- -- 1. Archivage
insert into job_history (
employee_id,
start_date,
end_date,
job_id,
department_id
)
select
employee_id,
e.hire_date,
current_date,
e.job_id,
e.department_id
from employee e
where e.employee_id = 101;
-- -- -- 2. Mettre à jour le job et département
update employee
set
job_id = "SA_REP",
department_id = 80,
hire_date = current_date
where employee_id = 101;
COMMIT;