Semaine 7
This commit is contained in:
38
Semaine_07/Jour_02/SQL_transactions.sql
Normal file
38
Semaine_07/Jour_02/SQL_transactions.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
-- 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;
|
||||
Reference in New Issue
Block a user