Lapchien
asked on
SQL Insert Trigger - Inserts everything!
I have a basic trigger, I want it to insert from table 1 to table 2 (in another db) whenever a new record is created in table 1. But each time a new record is added, the trigger inserts all records from table 1 to table 2, instead of just the new, single record!
What am I doing wrong? Trigger posted below:
What am I doing wrong? Trigger posted below:
USE [Training]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tr_Update_TrainFast]
ON [dbo].[TrainingEnquires]
FOR INSERT AS
INSERT INTO
TRAINFAST..Jobs
(JobTypeCode, TrainingCourses.TradeCode, DateTimeReceived, CallTypeId,
CustomerTitle, CustomerForename, CustomerSurname, [Property], Street,
Locality, Town, County, Postcode, TelephoneMobile, TelephoneLandline,
EmailAddress, StatusId, AccountCode, DateTimeRequired, Notes, SourceId)
SELECT
TrainingEnquires.CourseId, TrainingCourses.TradeCode, TrainingEnquires.DateTimeCreated,
1, TrainingEnquires.Title, TrainingEnquires.Forename, TrainingEnquires.Surname,
TrainingEnquires.Property, TrainingEnquires.Street, TrainingEnquires.Locality,
TrainingEnquires.Town, TrainingEnquires.County, TrainingEnquires.Postcode,
TrainingEnquires.TelephoneMobile, TrainingEnquires.TelephoneLandline,
TrainingEnquires.EmailAddress, 1, 1, TrainingEnquires.DateTimeCreated,
TrainingEnquires.Questions, TrainingEnquires.SourceId
FROM
TrainingEnquires
INNER JOIN TrainingCourses ON TrainingEnquires.CourseId = TrainingCourses.CourseId
replace "TrainingEnquires" by "inserted"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect thanks - can see that I need to use the systable inserted - I must have been inserting all the records each time!