Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - How to modify column default value?

How do I change my column's default value from None to something else? For example, I want my dates to have a default value of 0000-00-00 if I don't specify one when I create the row.

I understand this in phpMyAdmin, but I'm not sure how to do it via command prompt.

I also understand how to do this when adding a column. But all of my columns are made and have data in some of them.

ALTER TABLE table1 ADD COLUMN foo INT DEFAULT 0;

From searching, I found this line, but I'm not sure if that's what I want?

ALTER TABLE foobar_data MODIFY COLUMN col VARCHAR(255) NOT NULL DEFAULT '{}';
like image 789
User Avatar asked Jan 04 '14 04:01

User


People also ask

How do I change my default value?

Right-click the control that you want to change, and then click Properties or press F4. Click the All tab in the property sheet, locate the Default Value property, and then enter your default value. Press CTRL+S to save your changes.

What is the default value of column in MySQL?

MySQL | DEFAULT() Function DEFAULT value of a column is a value used in the case, there is no value specified by user.


1 Answers

Use ALTER TABLE to CHANGE or MODIFY the DEFAULT value of column. Check this link ALTER TABLE SYNTAX

ALTER TABLE `tableName` CHANGE `columnName` `columnName` DATE DEFAULT '0000-00-00'; 
ALTER TABLE `tableName` MODIFY `columnName` DATE DEFAULT '0000-00-00'; 
like image 60
Saharsh Shah Avatar answered Oct 19 '22 16:10

Saharsh Shah