Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alter a table column to nullable

Tags:

mysql

I want to alter a field to nullable and add the default value null.table name 'other_details' column name used_asset which is varchar(100)

ALTER TABLE `other_details` ALTER COLUMN `used_asset` varchar(100) DEFAULT NULL

above query shows error 'syntax error near varchar(100) DEFAULT NULL'

like image 998
user3386779 Avatar asked Jan 28 '26 04:01

user3386779


2 Answers

This came from phpmyadmin as preview SQL and it seems to work:

ALTER TABLE `other_details` CHANGE `used_asset` `used_asset` VARCHAR(100) NULL DEFAULT NULL;
like image 125
Petr Hejda Avatar answered Jan 29 '26 22:01

Petr Hejda


Try this

1) Using MODIFY

ALTER TABLE `other_details` MODIFY `used_asset` varchar(100) null;

2) Using CHANGE

Syntax

ALTER TABLE table_name CHANGE column_name column_name type DEFAULT NULL

Example

ALTER TABLE `other_details` CHANGE `used_asset` `used_asset` varchar(100) DEFAULT NULL;
like image 35
shubham715 Avatar answered Jan 29 '26 23:01

shubham715



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!