Reputation: 1
I am trying to create a table that includes a column that contains just the current date-not timestamp-using the MariaDB base. Which is the command that sets the content of the column as the current date upon table creation?
Upvotes: 0
Views: 774
Reputation: 339
Why on table create, as there will be no data, if you need a date and not datetime add to code, WELL before adding a trigger, keep business logic at the business layer not at storage layer.
Not your exact answer to the specific question but hopefully helpful advice, btw I don’t like triggers, so am a bit biased
Upvotes: 1
Reputation: 142298
MariaDB introduced DEFAULTs
for DATETIME
in 10.0.1.
See worklog . It is patterned after the MySQL 5.6.5 feature , which has examples.
If you want to default to only CURDATE()
, I think you are out of luck in MariaDB and MySQL.
A BEFORE INSERT
TRIGGER
with SET NEW.datetime_col = CURDATE()
should give you the functionality:
CREATE TRIGGER set_date BEFORE INSERT ON tbl
FOR EACH ROW SET NEW.datetime_col = CURDATE();
Upvotes: 0