开发者

Restrict users from changing rows inserted 3 hours ago in mysql

开发者 https://www.devze.com 2023-01-02 05:08 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消