I inserted a number of rows 3 hours ago and I don't want these rows to change. How can I write a sql statement that will compare current time with the timestamp in the row开发者_JAVA百科 and restrict users from changing it if above criteria is met.
Thanks
If you want to do it by using mysql, you will have to use the INTERVAL
statement which will allow you to "add" time to date functions... for instance:
UPDATE table
SET data = 'whatever'
WHERE NOW() - INTERVAL 3 HOUR < last_change
You can find more info and examples here: Date and Time Functions
You can use a WHERE clause in all updates:
UPDATE yourtable
SET foo = bar
WHERE inserttime > NOW() - interval 3 hour
精彩评论