Reputation: 7215
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'
Upvotes: 3
Views: 2342
Reputation: 1492
ALTER TABLE Table_Name MODIFY Column_Name DataType DEFAULT NULL;
Upvotes: 0
Reputation: 3302
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;
Upvotes: 3
Reputation: 43581
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;
Upvotes: 3