You are on page 1of 2

CREATE TRIGGER est_actualiza ON [dbo].

[Estudiante2]
FOR UPDATE
AS
declare @codigo int

select @codigo = codigoest


from deleted

if (update(nombrest))
begin
update estudiante
set estudiante.nivel = estudiante.nivel +2
where codigoest = @codigo
end

CREATE TRIGGER verificar_fecha ON [dbo].[Estudiante]


FOR INSERT
AS
declare @Fecha DATE
Select @Fecha = fechanac
from inserted

if @fecha > GetDate()


begin
ROLLBACK TRANSACTION
RAISERROR ('FECHA DESPUES DE HOY',16,4)
End

drop TRIGGER est_actualiza;


drop TRIGGER verificar_fecha;

Tabla2(codigo, nombre, edad)

create table tabla2(


codigo int, nombre varchar(20), edad int);

CREATE TRIGGER insertaest


ON dbo.estudiante
FOR insert, update
AS
BEGIN
declare @ed int
declare @cod int
declare @nom varchar(20)

select @ed = datediff(year, inserted.fechanac, getdate()),


@nom = inserted.nombrest,
@cod = inserted.codigoest
from inserted
insert into dbo.tabla2
values(@cod, @nom,@ed)

END

CREATE TRIGGER borraest


ON dbo.estudiante
FOR delete
AS
BEGIN
declare @cod int

select @cod = deleted.codigoest


from deleted

delete
from dbo.tabla2
where codigo =@cod

END

drop TRIGGER insertaest;

You might also like