简体   繁体   中英

MySQL set a default value YEAR type

The code below doesn't seem to work. I'm trying to set a default value and a time in the future (taking current year + 6 years). any idea?

ALTER TABLE users CHANGE COLUMN dpicture dpicture YEAR NULL DEFAULT 'YEAR(NOW())+6';

MySQL table defaults cannot be dynamic, except in the case of timestamp fields. There's also no such thing as a "year" field type in mysql, so your alter query is wrong on two levels.

You'll probably have to use a after-insert/update trigger to set the +6 years, and use a proper date or int field.

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