I have a question about triggers performance.
CREATE TABLE [dbo].[_test](
[ID] [INT] IDENTITY(1,1) NOT NULL,
[Date] [DATETIME] NULL,
[DateYearID] [INT] NULL,
[DateQuarterID] [INT] NULL,
[Date1] [DATETIME] NULL,
[Date1YearID] [INT] NULL,
[Date1QuarterID] [INT] NULL)
Now I want to have trigger that must update DateYearID and DateQuarterID columns if I update Date column (or insert a new row) , and must update Date1YearID and Date1QuarterID columns if I update Date1 column (or insert a new row). What is better, have a single trigger like
IF UPDATE(DATE)
UPDATE _test SET DateYearID = ... , DateQuarterID = ...
IF UPDATE (DATE1)
UPDATE _test SET Date1YearID = ... , Date1QuarterID = ...
or have two different triggers, first of them updating DateYearID,DateQuarterID columns, and the second one updateing DateYear1ID,DateQuarter1ID columns.
I am using SQL Server 2014.
Thanks a lot for help.
DateYearID
,DateQuartedID
,Date1YearID
andDate1QuartedID
are simply calculations on thedate
/date1
columns, I think you don't need a trigger at all and they can treated as computed columns. This is not clear from your question though.