PostgreSQL and Oracle make schema comments a one-liner. MySQL works but makes you restate the column to comment it, SQL Server needs a stored procedure call per comment, and SQLite only has the comments you wrote into the CREATE TABLE.
Where they differ
PostgreSQL and Oracle have a COMMENT ON statement. SQL Server stores comments as extended properties named MS_Description. MySQL keeps them as COMMENT clauses in CREATE and ALTER, so changing a column comment means restating the column definition. SQLite has no comment feature, but it keeps the original CREATE TABLE text, SQL comments included.
Comments are extended properties; add @level2type = N'COLUMN', @level2name = N'total' for a column. sp_updateextendedproperty changes one. SSMS shows MS_Description as the description.
PostgreSQL
COMMENT ON TABLE orders IS 'Orders placed by customers';
COMMENT ON COLUMN orders.total IS 'Order total incl. tax';
Stored in pg_description; psql's \d+ shows it. COMMENT ON … IS NULL (or an empty string) removes it.
MySQL
ALTER TABLE orders COMMENT = 'Orders placed by customers';
ALTER TABLE orders MODIFY COLUMN total DECIMAL(10,2)
COMMENT 'Order total incl. tax';
The column comment rides on MODIFY, so restate the exact type, NOT NULL and DEFAULT, or you change them too. A comment-only change is metadata-only in 8.0.
SQLite
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
total REAL -- order total incl. tax
);
SELECT sql FROM sqlite_schema WHERE name = 'orders';
No comment storage, but sqlite_schema (sqlite_master before 3.33) keeps the CREATE TABLE text with its -- comments. Changing one means rebuilding the table.
Oracle
COMMENT ON TABLE orders IS 'Orders placed by customers';
COMMENT ON COLUMN orders.total IS 'Order total incl. tax';
Same statement as PostgreSQL; IS '' removes the comment. Read them back from USER_TAB_COMMENTS and USER_COL_COMMENTS.
Questions that come up
How do I read comments back?
PostgreSQL: obj_description() and col_description(), or psql \d+. Oracle: the USER_ / ALL_TAB_COMMENTS and _COL_COMMENTS views. SQL Server: sys.extended_properties or fn_listextendedproperty. MySQL: the TABLE_COMMENT and COLUMN_COMMENT columns of information_schema.TABLES and COLUMNS.
Do comments appear in dumps?
pg_dump writes COMMENT ON statements, mysqldump keeps COMMENT clauses inside the CREATE statements, and Oracle Data Pump exports comments with the tables. SQL Server's Generate Scripts wizard includes extended properties when its 'Script extended properties' option is on.
Does a MySQL comment change rebuild the table?
Not in 8.0: changing only a column's comment is a metadata change. The risk is in the statement itself: MODIFY replaces the whole column definition, so a forgotten NOT NULL or DEFAULT really changes the column.