Documentos de Académico
Documentos de Profesional
Documentos de Cultura
--TABLA LIBROSPRESTADOS
CREATE TABLE LIBROSPRESTADOS
(Autogenerado integer not null,
IdLibro integer not null,
Estado integer not null
)
go
--Relacion entre Prestamo_LibrosPrestados
alter table LIBROSPRESTADOS
add
constraint R_Prestamo_LibrosPrestados
foreign key (Autogenerado)
references [PRESTAMO](Autogenerado),
constraint K_Primaria
primary key (Autogenerado, IdLibro)
go
--TABLA LIBRO
CREATE TABLE LIBRO
(IdLibro integer identity(1, 1) not null primary key,
Titulo varchar(60) not null,
ncopias integer not null
)
go
--Relacion entre LIBRO-LibrosPrestados
alter table LIBROSPRESTADOS
add
constraint R_Libro_LibrosPrestados
foreign key (IdLibro)
references [LIBRO](IdLibro)
go
use BIBLIOTEKA
go
create trigger T_Devolucion
on LIBROSPRESTADOS
for Update
as
Begin
begin transaction
declare @IdLibro integer
declare @cuentaLibros integer
select IdLibro=@IdLibro
from deleted
select @cuentaLibros=ncopias
from LIBRO
where IdLibro=@IdLibro
UPDATE LIBRO
set ncopias+=1
where IdLibro=@IdLibro
commit transaction
End
go