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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:28:27+00:00 2026-05-14T05:28:27+00:00

I have a load of tables all with the same 2 datetime columns (lastModDate,

  • 0

I have a load of tables all with the same 2 datetime columns (lastModDate, dateAdded).
I am wondering if I can set up global Insert Update trigger for these tables to set the datetime values. Or if not, what approaches are there?

Any pointers much appreciated

  • 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-14T05:28:27+00:00Added an answer on May 14, 2026 at 5:28 am

    You can use DEFAULT values for the inserts (dateAdded) and a TABLE trigger for the UPDATE.

    Something like

    CREATE TABLE MyTable (
            ID INT,
            Val VARCHAR(10),
            lastModDate DATETIME DEFAULT CURRENT_TIMESTAMP, 
            dateAdded DATETIME DEFAULT CURRENT_TIMESTAMP
    )
    GO
    
    CREATE TRIGGER MyTableUpdate ON MyTable
    FOR UPDATE
    AS
    UPDATE  MyTable
    SET     lastModDate = CURRENT_TIMESTAMP
    FROM    MyTable mt INNER JOIN
            inserted i ON mt.ID = i.ID
    GO
    
    INSERT INTO MyTable (ID, Val) SELECT 1, 'A'
    GO
    
    SELECT *
    FROM MyTable
    GO
    
    UPDATE MyTable
    SET Val = 'B' 
    WHERE ID = 1
    GO
    
    SELECT *
    FROM MyTable
    GO
    
    DROP TABLE MyTable
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 5GB database, all tables are MyISAM. It runs into heavy load
I have data in different tables but in the same database, all of which
I have a script that drops a load of tables using DROP TABLE IF
I have a data-upload function that load some data into several tables and processes
I have multiple select statements from different tables on the same database. I was
I'm planning to have 20 or more sites in the same database tables. Like
Suppose I have a custom file format, which can be analogous to N tables.
Hy all, I have three tables Child, Pet and Toy. Pet has a reference
I have multiple data tables per page, ranging from 4 to 8 ish. All
I have a page where I load a table of information using ajax. Once

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.