Hello
Our original database has called first, middle, last for names of people. We have now created fields called firstname, middlename, and lastname. While we are going through this transition I have created a trigger to copy data from first to firstname, middle to middlename, and last to lastname anytime one the previous fields receive an update or insert. The issue is when we batch upload files into our database it slows everything way down and may cause other events to timeout.
Below is my code:
USE [Database]
GO
/****** Object: Trigger [dbo].[CopyFirstName] Script Date: 07/15/2009 08:35:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[CopyFirstName]
ON [dbo].[Patients]
AFTER INSERT,UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF UPDATE([First]) BEGIN
SET NOCOUNT ON;
declare @ChangedField nvarchar(50);
select @ChangedField = [First] from inserted
update dbo.Patients set FirstName = @ChangedField where [First] = @ChangedField
END
end
Could this be improved or done another way?