Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BootcampWebDia6
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cesar Giulano Gonzalez Maqueda
BootcampWebDia6
Commits
e52efc63
Commit
e52efc63
authored
Oct 22, 2021
by
Cesar Giulano Gonzalez Maqueda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trigger
parent
e93645af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
src/trigger.sql
+46
-0
No files found.
src/trigger.sql
0 → 100644
View file @
e52efc63
/*
En el dvdrental cree una tabla llamada registro_inventory con las siguientes columnas:
1. Fecha
2. film_id.(Foreign Key relacionada con la tabla film)
3. Store_id.(Foreign Key relacionada con la tabla store)
Cree un TRIGGER en la tabla inventory que se ejecute despus de cualquier
actualizacin(UPDATE) en la tabla de inventory.
La funcin de TRIGGER insertar viejos valores de la tabla inventory en una nueva fila en la
tabla registro_inventory.
Notas:
Se puede acceder a viejos valores a travs del sintaxis OLD.film_id y OLD.store_id. Estos
valores estn disponibles solamente en la funcin de TRIGGER
*/
create
table
if
not
exists
registro_inventory
(
id_registro
serial
primary
key
,
fecha
timestamp
,
film_id
int
not
null
,
store_id
int
not
null
,
constraint
fk_film
foreign
key
(
film_id
)
references
film
(
film_id
),
constraint
fk_store
foreign
key
(
store_id
)
references
store
(
store_id
)
);
CREATE
function
insert_old_inventory
()
RETURNS
trigger
AS
$
insert_old_inventory
$
BEGIN
IF
NEW
.
film_id
IS
NULL
THEN
RAISE
EXCEPTION
'Film Id no puede ser nulo'
;
END
IF
;
IF
NEW
.
store_id
IS
NULL
THEN
RAISE
EXCEPTION
'Store_id no puede ser nulo'
;
END
IF
;
insert
into
registro_inventory
(
id_registro
,
fecha
,
film_id
,
store_id
)
values
(
default
,
old
.
last_update
,
old
.
film_id
,
old
.
store_id
);
RETURN
NEW
;
END
;
$
insert_old_inventory
$
LANGUAGE
plpgsql
;
CREATE
trigger
if
not
exists
insert_old_inventory
AFTER
UPDATE
ON
inventory
FOR
EACH
ROW
EXECUTE
FUNCTION
insert_old_inventory
();
---Test
update
inventory
set
store_id
=
2
where
inventory_id
=
1
;
select
*
from
inventory
i2
where
inventory_id
=
2
select
*
from
registro_inventory
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment