Create trigger Sql server

0

I have this statement to import data to the test table, what I need is to create a trigger.

BULK
INSERT PRUEBA
FROM 'C:\prueba.CSV'
WITH
(
-- seteamos el separador de campos
FIELDTERMINATOR = ',',
--seteamos el separador de registro
ROWTERMINATOR = '\n'
);
GO
    
asked by R.Priego 27.12.2016 в 11:49
source

1 answer

1

The next trigger (named NameTrigger) will be executed later (AFTER) of each insert in the TEST table, where I put the PRINT you should code the function you want the trigger to perform, if you need more help, expand the info of the ask.

 CREATE TRIGGER NombreTrigger ON PRUEBA
    AFTER INSERT 
    AS
    PRINT 'Se inserto una fila';

EDIT: As comrade @Lamak says, you should add the FIRE_TRIGGERS argument to your BULK INSERT

BULK
INSERT PRUEBA
FROM 'C:\prueba.CSV'
WITH
(
-- seteamos el separador de campos
FIELDTERMINATOR = ',',
--seteamos el separador de registro
ROWTERMINATOR = '\n',
FIRE_TRIGGERS
);
GO
    
answered by 27.12.2016 в 12:16