Script for all fields in the database:
SELECT table_name, column_name, CONCAT('ALTER TABLE `', table_name, '` CHANGE `', column_name, '` `', column_name, '` ', column_type, ' ', IF(is_nullable = 'YES', '' , 'NOT NULL '), IF(column_default IS NOT NULL, concat('DEFAULT ', IF(column_default = 'CURRENT_TIMESTAMP', column_default, CONCAT('\'',column_default,'\'') ), ' '), ''), IF(column_default IS NULL AND is_nullable = 'YES' AND column_key = '' AND column_type = 'timestamp','NULL ', ''), IF(column_default IS NULL AND is_nullable = 'YES' AND column_key = '','DEFAULT NULL ', ''), extra, ' COMMENT \'', column_comment, '\' ;') as script FROM information_schema.columns WHERE table_schema = 'my_database_name' ORDER BY table_name , column_name
- Export all to CSV
- Open it in your favorite csv editor
Note. You can improve only one table if you want
The solution given by @Rufinus is great, but if you have automatic increments, it will break it.
workdreamer Jul 22 '13 at 15:29 2013-07-22 15:29
source share