<p>I have the following table in MySQL (version 5):</p>

<pre><code>id     int(10)       UNSIGNED             No    auto_increment              
year   varchar(4)    latin1_swedish_ci    No             
title  varchar(250)  latin1_swedish_ci    Yes   NULL         
body   text          latin1_swedish_ci    Yes   NULL
</code></pre>

<p>And I want the db to auto add the current year on insert, I've tried the following SQL statement:</p>

<pre><code>ALTER TABLE `tips` CHANGE `year` `year` VARCHAR(4) NOT NULL DEFAULT year(now())
</code></pre>

<p>But it gives the following error:</p>

<pre><code>1067 - Invalid default value for 'year'
</code></pre>

<p>What can I do to get this functionality? Thanks in advance!</p>

The following should work:
```
```
ALTER TABLE tips MODIFY COLUMN year YEAR(4) NOT NULL DEFAULT CURRENT_TIMESTAMP
```
```
Please see
Year Data Type
for further information.
So, I tested this once I got access and it doesn't work. As another poster pointed out CURRENT_TIMESTAMP only works on the
TIMESTAMP
data type.
Is there a specific problem with storing a complete time stamp and then only using the year in your code? If not, then I would recommend storing this value as a timestamp.
Your other option would be to create a
trigger
:
```
```
CREATE TRIGGER example_trigger AFTER INSERT ON tips
FOR EACH ROW BEGIN
UPDATE tips SET year = YEAR(NOW()) WHERE tip_id = NEW.tip_id
END;
```
```
Otherwise, assign this value to the INSERT statement from within your code.
The best solution in your case will depend entirely on the circumstances surrounding your particular application.