Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove default constraint from column in Db2

I had a table STUDENT_TB, which had column STUDENT_ID, NAME, AGE. I added a column with a following command :-

alter table STUDENT_TB add DOB TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP

as for the DOB column i didn't wanted it to be null. Now i need to remove that default constraint.

I tried searching but not got any success.

Regards.

like image 744
M.J. Avatar asked Oct 04 '11 11:10

M.J.


People also ask

How do I drop a DEFAULT constraint?

How to Remove Default Constraints in SQL? To remove an existing DEFAULT constraint on any column, you can use the ALTER TABLE statement along with the DROP keyword in SQL. ALTER TABLE is used because the table is being modified or altered, and DROP is used to remove the constraint from the column of the table.

How do I delete a constraint in db2?

To remove a constraint, use the ALTER TABLE statement. To make this key a unique key, replace the keyword PRIMARY with UNIQUE.


2 Answers

I tried with this and it worked properly

alter table STUDENT_TB alter DOB drop DEFAULT
like image 192
M.J. Avatar answered Oct 29 '22 08:10

M.J.


ALTER TABLE STUDENT_TB ALTER COLUMN DOB DROP NOT NULL

like image 36
egbokul Avatar answered Oct 29 '22 08:10

egbokul