patternsqlMinor
After Insert Trigger never fires using Import Wizard
Viewed 0 times
afterneverwizardtriggerinsertusingfiresimport
Problem
Using Import Wizard I tried importing tables
These 2 table structures already exist in SQL Server and they are related with
Any time I import tables,
The trigger never fires!?
tcc_Block and PROJECT_IDENTITY. These 2 table structures already exist in SQL Server and they are related with
ProjectID columns. PROJECT_IDENTITY has ProjectID as PK and tcc_Block as FK key. Any time I import tables,
ProjectID in parent table is created and incremented, but the one in child table is always Null. The trigger never fires!?
-- On tcc_Block table I need to do the update (below) AFTER INSERT
-- Tried Trigger, but none would work.
ALTER TRIGGER [dbo].[InsertTest]
ON [dbo].[tcc_Block]
AFTER INSERT
NOT FOR REPLICATION
AS
BEGIN
DECLARE @proj int;
SELECT @proj =max(ProjectID)
FROM PROJECT_IDENTITY ;
UPDATE tcc_Block
SET ProjectID = @proj
WHERE ProjectID is null ;
END;
GOSolution
The SQL Server Import and Export Wizard does not expose a way to enable triggers directly.
You could save the result as an SSIS package, then edit that to enable the
Alternatively, and probably more simply, you could choose to use one of the other data import methods that more easily allow you to specify that triggers should be fired.
Related official documentation:
Bulk Import and Export of Data (SQL Server)
Controlling Trigger Execution When Bulk Importing Data
You could save the result as an SSIS package, then edit that to enable the
FIRE_TRIGGERS option in the component it uses.Alternatively, and probably more simply, you could choose to use one of the other data import methods that more easily allow you to specify that triggers should be fired.
Related official documentation:
Bulk Import and Export of Data (SQL Server)
Controlling Trigger Execution When Bulk Importing Data
Context
StackExchange Database Administrators Q#116848, answer score: 3
Revisions (0)
No revisions yet.