Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Since Triggers are a contentious subject, can someone please tell me if mine is written correctly?

$
0
0
/****** Object: Table [dbo].[TriggerCB] Script Date: 5/12/2014 9:20:12 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[TriggerCB]( [IDa] [int] IDENTITY(1,1) NOT NULL, [LocationState] [varchar](2) NULL, [StateCount] [int] NULL, CONSTRAINT [PK__CBtriggerid] PRIMARY KEY CLUSTERED ( [IDa] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[TriggerCBCount]( [IDb] [int] IDENTITY(1,1) NOT NULL, [StateCountb] [int] NULL, [LocationState2] [varchar](2) NULL, CONSTRAINT [PK__CBtriggerid2] PRIMARY KEY CLUSTERED ( [IDb] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TRIGGER [dbo].[StateCountInsert2x] ON [dbo].[TriggerCB] FOR INSERT ASBEGIN UPDATE u SET u.StateCountb = u.StateCountb + d.cnt FROM [dbo].[TriggerCBCount] u inner join ( SELECT LocationState, count(*) as cnt FROM inserted GROUP BY LocationState ) d --ON u.IDb = d.IDa ON u.LocationState2 = d.LocationStateENDGOThe trigger works fine, i just want to make sure it is written correctly.I am doing the data import via an SSIS project.Thanks

Viewing all articles
Browse latest Browse all 3145

Latest Images

Trending Articles



Latest Images