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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:04:00+00:00 2026-06-15T07:04:00+00:00

Is it possible to have a timestamp constraint in mysql that MUST come from

  • 0

Is it possible to have a timestamp constraint in mysql that MUST come from the system and can not otherwise be provided in the insert or update query?

Is it possible to keep a table from being updated with a constraint? I understand how to keep a mysql user from updating a table with GRANT but in my case a constraint may be preferred as it is my goal to guarantee the timestamp of the record regardless of user including root.

  • 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-15T07:04:01+00:00Added an answer on June 15, 2026 at 7:04 am

    What you can do is to overwrite the value on INSERT and UPDATE using a trigger

    So no matter what the query sets, the value of your desired timestamp field will always be the system time.

    DELIMITER ;;
    
    CREATE TRIGGER before_yourtable_insert 
    BEFORE INSERT ON yourtable
    FOR EACH ROW
    BEGIN
        SET NEW.datefield := CURRENT_TIMESTAMP;
    END;;
    
    CREATE TRIGGER before_yourtable_update 
    BEFORE UPDATE ON yourtable
    FOR EACH ROW
    BEGIN
        SET NEW.datefield := CURRENT_TIMESTAMP;
    END;;
    
    DELIMITER ;
    

    EDIT 1:
    Just realized you actually wanted to prevent that the once set system time could be updated later.
    Slightly modify your UPDATE trigger to have this job done.

    SET NEW.datefield := OLD.datefield resets the value to the old value on each update

    CREATE TRIGGER before_yourtable_update 
    BEFORE UPDATE ON yourtable
    FOR EACH ROW
    BEGIN
        SET NEW.datefield := OLD.datefield;
    END;;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have JavaScript compute a timestamp returned from PHP's time() function
I have a process that extracts customer info from multiple databases (MySql) based on
I have a process that extracts customer info from multiple databases (MySql) based on
Is it possible to set a field to Timestamp but not have it change
Is it possible in javascript to convert some date in timestamp ? i have
Is it possible to have a free iPhone app that has say an initial
I have the following table CREATE TABLE [dbo].[LogFiles_Warehouse]( [id] [int] IDENTITY(1,1) NOT NULL, [timestamp]
Possible Duplicate: Add 1 hour to datetime datatype I have a timestamp stored in
Possible Duplicate: Convert a Unix timestamp to time in Javascript I have been storing
I have a VARCHAR field completion_date that contains a timestamp date (ex 1319193919). Is

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.