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?
Asked
Active
Viewed 544 times
0
-
It depends on what version you are running! – Rick James Mar 26 '18 at 22:47
-
Since this question is specifically about MariaDB, I am reopening. The alleged [dup](https://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column) was specific to MySQL. – Rick James Mar 26 '18 at 22:50
2 Answers
1
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

ekydfejj
- 339
- 2
- 14
0
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();

Rick James
- 135,179
- 13
- 127
- 222