owl

Friday, September 25, 2009

Trigger to insert in another table

ALTER TRIGGER onInsert ON Employee
FOR INSERT
AS

DECLARE @Age INT
DECLARE @message VARCHAR(50)
SET @Age=(SELECT age FROM inserted)

IF(@Age>20 and @Age<50)
BEGIN
INSERT INTO Employee1([Name],Age)
SELECT [Name],Age FROM inserted i
END
ELSE
BEGIN
SELECT @message 'message'
END

No comments: