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 5843123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:06:38+00:00 2026-05-22T12:06:38+00:00

I have a trigger that automatically sets the CreationDate and ModifiedDate of the given

  • 0

I have a trigger that automatically sets the CreationDate and ModifiedDate of the given entry to the current UTC time whenever a value is entered. (CreationDate will remain the same thereafter, while ModifiedDate will be updated on each update via another trigger).

I want to make sure that inserted-and-never-updated items will have exactly the same value for CreationDate and ModifiedDate, so I’ve used a variable like this:

DECLARE @currentTime DATETIME
SELECT @currentTime = GETUTCDATE()
UPDATE dbo.MyTable SET CreationDate = @currentTime, ModifiedDate = @currentTime
    ...

In my imperative-programming mentality, I am assuming this prevents GETUTCDATE() from being called twice, and potentially producing slightly different results. Is this actually necessary? If not, would this be more expensive, less expensive, or exactly the same as the following code?

UPDATE dbo.MyTable SET CreationDate = GETUTCDATE(), ModifiedDate = GETUTCDATE()
    ...
  • 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-05-22T12:06:39+00:00Added an answer on May 22, 2026 at 12:06 pm
    DECLARE @Counter INT = 1
    
    WHILE (1 = (SELECT 1 WHERE GETUTCDATE()  = GETUTCDATE()))
    SET @Counter = @Counter+1
    
    SELECT @Counter /*Returns almost immediately with a number in the 000s for me.*/
    

    And just to prove this happens when in the SELECT list also.

    DECLARE @T TABLE 
    (
    rownum INT IDENTITY(1,1) PRIMARY KEY,
    d1 datetime,
    d2 datetime
    )
    
    WHILE (NOT EXISTS(SELECT * FROM @T WHERE d1 <> d2))
        BEGIN
        DELETE FROM @T
        INSERT INTO @T 
        SELECT GETUTCDATE(),GETUTCDATE()
        END
    
    SELECT * FROM @T
    

    BTW: IF for some reason you want to evaluate GETUTCDATE() on a per row basis you can wrap it in a scalar UDF.

    CREATE FUNCTION dbo.GETUTCDATE()
    RETURNS DATETIME
    WITH SCHEMABINDING
    AS
    BEGIN
    RETURN GETUTCDATE()
    END
    GO
    
    SELECT GETUTCDATE(),dbo.GETUTCDATE()
    FROM master..spt_values
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an auditing trigger that automatically places the time something was updated and
We have created a table with a trigger that updates a ModifiedDate field in
I have a trigger that stores changes made in a separate table when a
I have this Trigger in Postgresql that I can't just get to work (does
I have a table in a SQL Server 2005 database with a trigger that
I have a table that has an insert trigger on it. If I insert
I have a number of tables that use the trigger/sequence column to simulate auto_increment
I have a few UIButtons that I'd like to trigger short 5-10 frame animations
I have a button that when clicked displays some information, can i manually trigger
I have a page that automatically refreshes content via Ajax. I want this to

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.