简体   繁体   中英

Column constraint: allow growing only value

I would like to restrict values in mySql table column to satisfy the rule the new values inserted must be greater than any existing ones. As I cannot find any other than UNIQUE and AUTOINCREMENT constraints, I would like to ask, if there is any possibility to reach such functionality in mySql.

You would have to implement such functionality using a before insert trigger.

MySQL supports the syntax of check constraints, but it doesn't actually implement the logic. That leaves trigger.

Also, there might be additional options if you edit your question and explain what the column is representing. For an id type of column, for instance, you can use autoincrement . If it is a cumulative sum of some sort, then perhaps storing the changes would make more sense than storing the total.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM