There is a table structure, for example, like this:

CREATE TABLE `user_visit` ( `visit_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `application` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `user_id` int(11) unsigned NOT NULL, `referrer` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `ip` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `USER_AGENT` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`visit_id`), KEY `FK_user_user_visit` (`user_id`), CONSTRAINT `FK_user_user_visit` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

There was a need to add comments to the table itself and to each column (teamwork is all things).

But, unfortunately, I did not find the syntax of how to add comments to columns and a table in MySql. Tell me, please, how can this be done?

    2 answers 2

     CREATE TABLE `my_super_table` ( `my_super_column` INT NOT NULL AUTO_INCREMENT COMMENT 'My super comment' ) COLLATE='utf8_general_ci' ENGINE=InnoDB; 

    Update

     ALTER TABLE `my_super_table` CHANGE COLUMN `my_super_column` `my_super_column` INT NOT NULL AUTO_INCREMENT COMMENT 'My super comment' 
    • And add a comment to an existing column via modify? - Nepster
    • Updated the answer - dlarchikov
    • A few hours soared the rules of migration, adding comments to each field. = (On what you will not go for the sake of the team. Thank you very much. - Nepster

    How to add comments to columns and table in MySql?

     ALTER TABLE table-name COMMENT='....'; 
    • in question, the author asks "how to add comments to the columns and table in MySql". Perhaps you should expand your answer so that it answers the whole question. - Alex