![]() ![]() The solution given by is great but if you have auto increments it will break it. Note: You can improve to only one table if you prefer IF(column_default IS NULL AND is_nullable = 'YES' AND column_key = '','DEFAULT NULL ', ''), ALTER TABLE db-name.table-name CHANGE COLUMN column-name column-name DECIMAL (15,6) Share. IF(column_default IS NULL AND is_nullable = 'YES' AND column_key = '' AND column_type = 'timestamp','NULL ', ''), Use the SQl Query for Change data type of Mysql Column. IF(is_nullable = 'YES', '', 'NOT NULL '), Script for all fields on database: SELECT Similarly, if the column is defined as NOT NULL or has a DEFAULT value, these details need to be included when doing a MODIFY or CHANGE on the column or they will be lost. For example, if you MODIFY an AUTO_INCREMENT column, you need to explicitly specify the AUTO_INCREMENT modifier again in the MODIFY clause, or the column will cease to be an AUTO_INCREMENT column. This protects you from accidentally losing an important part of your column definition by not realising that you need to include it in your MODIFY or CHANGE clause. * Whenever you use MODIFY or CHANGE clauses in an ALTER TABLE statement, I suggest you copy the column definition from the output of a SHOW CREATE TABLE statement. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Look, I''m a comment!', > int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Look, I''m a comment!' > `id` int(10) unsigned NOT NULL AUTO_INCREMENT, ![]() Your new comment with the column comment you want.įor example.your_previous_column_definition with the column's column_definition, which I recommend getting via a SHOW CREATE TABLE YourTable command and copying verbatim to avoid any traps.*.your_column with the name of your comment.Your_previous_column_definition COMMENT "Your new comment"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |