/*Tanto para INSERT y UPDATE la tabla usada en los TRIGGER es INSERTED. para los delete es DELETED*/
USE [Gestion]
GO
/****** Object: Trigger [dbo].[upd_requerimientos] Script Date: 27/09/2015 12:02:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Create Trigger (New Menu).SQL
ALTER TRIGGER [dbo].[upd_requerimientos] ON [dbo].[REQUERIMIENTO]
AFTER UPDATE
AS
BEGIN
DECLARE @id_requerimiento INT
,@id_archivo INT
SELECT @id_requerimiento = ID_REQUERIMIENTO
,@id_archivo = ID_ARCHIVO
FROM inserted
UPDATE Gestion..REL_REQUERIMIENTO_ARCHIVO
SET ID_ARCHIVO = @id_archivo
WHERE ID_REQUERIMIENTO = @id_requerimiento
END
/************************************************************************/
/*TABLAS AFECTADAS PARA TENER UNA IDEA*/
CREATE TABLE [dbo].[REQUERIMIENTO](
[ID_REQUERIMIENTO] [int] IDENTITY(1,1) NOT NULL,
[ID_PROYECTO] [int] NULL,
[NOMBRE_REQUERIMIENTO] [varchar](max) NULL,
[DESCRIPCION_REQUERIMIIENTO] [varchar](max) NULL,
[TIPO_REQUERIMIENTO] [varchar](50) NULL,
[ESTADO] [tinyint] NULL,
[ID_ARCHIVO] [int] NULL,
CONSTRAINT [PK_REQUERIMIENTO] PRIMARY KEY CLUSTERED
(
[ID_REQUERIMIENTO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[REL_REQUERIMIENTO_ARCHIVO](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ID_REQUERIMIENTO] [int] NULL,
[ID_ARCHIVO] [int] NULL,
CONSTRAINT [PK_REL_REQUERIMIENTO_ARCHIVO] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
No hay comentarios:
Publicar un comentario