Search code examples
mysqlsqldefault-constraint

the default value must be a constant; why?


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?


Solution

  • 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();