Sei sulla pagina 1di 1

create trigger tr_ejercicio5 on alumno for insert as declare @matricula char(9), @curso smallint select @matricula=matricula, @curso=curso from

inserted insert into notas select @matricula, asignatura, null, null, null, null from asigxcurso where curso=@curso --Ejecucin del trigger-insert into alumno values ('555','peperico','1') create procedure tr_ejercicio6 @fecha datetime as begin tran begin try insert into AlquileresAntiguos select CodSocio, IdPelicula, FechaAlquiler, FechaDevolucion, Devuelto from Alquiler where Devuelto=1 and FechaDevolucion<@fecha delete from Alquiler where FechaDevolucion<@fecha and Devuelto=1 commit tran end try begin catch print No ha funcionado rollback tran end catch --Ejecucin del procedimiento Exec tr_ejercicio6 10/05/2011 create procedure tr_ejercicio2.4 @origen char (20), @destino char (20), @importe money as declare @saldo money set @importe=ABS (@importe) begin try begin tran update cuentas set saldo=saldo-@importe where numcuenta=@origen update cuentas set saldo=saldo+@importe where numcuenta=@destino select saldo=@saldo from cuentas where numcuenta=@origen insert into movimientos values (@origen, getdate(), Transferencia a+@destino, -@importe, @saldo) select @saldo=saldo from cuentas where numcuenta=@destino insert into movimientos values (@destino, getdate(), Tranferencia de+ @origen, +@importe, @saldo) commit tran end try begin catch print (Se ha desecho la transeccin) rollback tran end catch create procedure tr_ejercicio3 @fecha1 smalldatetime, @fecha2 smalldatetime, @nif nvarchar (10), @codcasa char (10) as declare @casa1 int, @casa2 int, @casa3 int, @casa4 int select @casa1=count(*) from reservas where @fecha1 between fecha_entrada and fecha_saluda and codcasa=@codcasa select @casa2=count(*) from reservas where fecha_entrada between @fecha1 and @fecha2 and codcasa=@codcasa select @casa3=count(*) from reservas where @fecha2 between fecha_entrada and fecha_salida and codcasa=@codcasa if @casa1=0 and @casa2=0 and @casa3=0 insert into reservas values (@codcasa, getdate(), @fecha1, @fecha2, @nif) else print Est ocupado --Ejecucin del procedimiento exec tr_ejercicio3 create procedure tr_ejercicio3.5 @zona varchar (30), @plazas tinyint, @fecha1 smalldatetime, @fecha2 small datetime as (select alojamientos.codcasa, nombre from alojamientos where zona=@zona and plazas=@plazas) except (select alojaminetos.codcasa, nombre from reservas inner join alojamientos on alojamientos.codcasa= reservas.codcasa where zona=@zona and plazas=@plazas and @fecha1 between fechaentrada and fechasalida or fechaentrada between @fecha1 and @fecha2 or @fecha2 between fechaentrada and fechasalida) --Ejecucin del procedimiento-exec tr_ejercicio3.5 Serrania de Ronda, 6, 10-02-2013, 25-02-2013

Potrebbero piacerti anche