Showing posts with label Mysql ALTER DROP DEFAULT. Show all posts
Showing posts with label Mysql ALTER DROP DEFAULT. Show all posts

Wednesday, 8 October 2014

Mysql - Alter/Remove default value of a column

Mysql Tech Byte: 
We can remove just the default values of a column(s) in Mysql using the following command. 

Single Column: 
ALTER TABLE < TableName > ALTER < ColumnName > DROP DEFAULT; 

If we execute the above statement, the default value for that particular column will be dropped. 

Multiple Columns: 
ALTER TABLE < TableName > ALTER < ColumnName1 > DROP DEFAULT, ALTER < ColumnName2 > DROP DEFAULT; 

Modify a default value: 

ALTER TABLE < TableName > ALTER < ColumnName1 > DROP DEFAULT, ALTER < ColumnName2 > SET DEFAULT 100; 

This statement removes a default value for ColumnName1 and alters the DEFAULT value of ColumnName2 from its previous value to the new value 100.