0

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?

3

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.