I want to update a column with a default value. I do that like so:
ALTER TABLE `db`.`tbl` ALTER COLUMN `some_timestamp` SET DEFAULT current_timestamp();
that works fine. I also want to add NOT NULL. How do I do that?
I want to update a column with a default value. I do that like so:
ALTER TABLE `db`.`tbl` ALTER COLUMN `some_timestamp` SET DEFAULT current_timestamp();
that works fine. I also want to add NOT NULL. How do I do that?
Like so:
ALTER TABLE `db`.`tbl` MODIFY `some_timestamp` TIMESTAMP NOT NULL DEFAULT current_timestamp();
ALTER COLUMN
is only used for setting defaults in MySQL; MODIFY <colname> <colspec>
modifies a column spec but doesn't rename it. To rename also, use CHANGE <oldname> <newname> <colspec>
and specify oldname newname
you can add multiple constrains by following way also ALTER TABLE MEMBER ADD CONSTRAINT U_MEMBERID UNIQUE(MEMBER_ID), primary key (MEMBER_ID), CONSTRAINT Sys_date DEFAULT GETDATE() FOR Sys_date;