Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:33:48+00:00 2026-06-06T05:33:48+00:00

I have created a table with the following columns: ObservationId, FirstCreatedDate, description, … …

  • 0

I have created a table with the following columns: ObservationId, FirstCreatedDate, description, … … and LastUpdatedDate in SQL Server 2008 R2. The ObservationId is an identity with increment by 1.

I need to create two triggers, one for INSERT and the other for UPDATE. On new record inserted, the INSERT trigger will update FirstCreatedDate column by getting the current datetime; while on existing record updated, the UPDATE trigger will update LastUpdatedDate colunm by getting the current datetime.

I have failed in doing this as I am guessing the identify might be the problem.

Could anyone give me a hand? Thanks!

Cheers,
Alex

ALTER TRIGGER [dbo].[T_InsertNewObservation] ON [dbo].[GCUR_OBSERVATION] 
  AFTER INSERT
AS 
BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  SET NOCOUNT ON;

  -- Insert statements for trigger here
  UPDATE GCUR_OBSERVATION SET GCUR_OBSERVATION.FirstCreatedDate = getdate()
  FROM GCUR_OBSERVATION a INNER JOIN INSERTED ins ON a.ObservationId = ins.ObservationId

END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:33:49+00:00Added an answer on June 6, 2026 at 5:33 am

    I think you are mostly correct but are not accessing the INSERTED or DELETED tables correctly.

    ALTER TRIGGER [dbo].[T_InsertNewObservation] ON [dbo].[GCUR_OBSERVATION] 
      AFTER INSERT
    AS 
    BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
    
      -- get the last id value of the record inserted or updated
      DECLARE @id INT
      SELECT @id = [ObservationId]
      FROM INSERTED
    
      -- Insert statements for trigger here
      UPDATE GCUR_OBSERVATION 
      SET GCUR_OBSERVATION.FirstCreatedDate = GETDATE()
      WHERE [ObservationId] = @id 
    
    END
    

    PS. Hopefully this works as I wrote it in notepad and haven’t tested it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a table with the following structure- $sql = CREATE TABLE followers
I have a table that has the following columns Id ForeignKeyId AttributeName AttributeValue Created
I have created table #temp with columns id as int identity(1,1) and name as
I have a table with the following columns: playlistid trackname playstatus likes dislikes created
I have created a mysql table with the following columns... item_price, discount, delivery_charge, grand_total
I have a computed column created with the following line: alter table tbPedidos add
I have a Model created with a table called Customers. It contains the following
I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int)
I have the following table: $sql = CREATE TABLE received_queries ( sender_screen_name varchar(50), text
I have the following data in a database table, Columns : Date, Hour(from 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.