in this said
the default value must be a constant; it cannot be a function or an expression
can you tell me why ? why we must give constant default value?
in this said
the default value must be a constant; it cannot be a function or an expression
can you tell me why ? why we must give constant default value?
This is a limitation in MySQL.
You can either use another RDBMS or get around the problem using a trigger.
CREATE TRIGGER yourtable_insert BEFORE INSERT ON `yourtable`
FOR EACH ROW SET NEW.youraddedcolumn = NOW(), NEW.yourupdatedcolumn = NOW();
One reason I can think of is ambiguity. Should the expression be evaluated before storing it as a default or for each INSERT?
Note that there's one non-constant value you can use in a table definition:
stamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
This can only be used on a TIMESTAMP
column, but it's useful enough.