Create a Trigger for table and then insert data into another table

OBJECT:  

 

A>  CREATE A TRIGGER FOR A TABLE.

B>   AND THEN INSERT DATA INTO ANOTHER TABLE.


BASIC SYNTAX

CREATE TRIGGER TRIGGER NAME

          ON TABLE NAME

          FOR INSERT

          AS

BEGIN

DECLARE 

@COLUMANNAME1     =@COLUMANNAME1,

@COLUMANNAME2     =@COLUMANNAME2

SELECT @COLUMANNAME1    =(SELECT COLUMANNAME1 FROM INSERTED)

SELECT @COLUMANNAME2    =(SELECT COLUMANNAME2 FROM INSERTED)

INSERT INTO MIRRORTABLENAME (IN WHICH YOU WANT TO INSERT DATA)

 (

COLUMANNAME1,

COLUMANNAME2

 )

 
         VALUES

(

@COLUMANNAME1,

@COLUMANNAME1    

)    

END

Ebook Download
View all
Learn
View all