0

Im trying to add a new column to my SQL table i want the data type to be TIME and the default value to be CURRENT_TIME. This is my query.

ALTER TABLE tuesday_records ADD cur_time TIME DEFAULT CURRENT_TIME

And this is the error message i get.

Error
SQL query:


ALTER TABLE tuesday_records ADD cur_time TIME DEFAULT CURRENT_TIME
MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CURRENT_TIME' at line 1
Balor9914
  • 17
  • 4

1 Answers1

0

You can do what you want with generated columns:

create table t (
    id int auto_increment primary key,
    x int,
    t timestamp default now(),
    tt time generated always as (time(t))
);

That is, add a timestamp column and then extract the time.

Here is a db<>fiddle.

Although this answers your question, I'm not sure if it is the best approach to your overall problem.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786