Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
Documenting cleaning rules with COMMENT ON TABLE and COMMENT ON COLUMN
COMMENT ON saves a note on a table or a column, inside the database, where the next analyst will find it.
Try this lesson free →Example
Leaving notes on tables and columns
COMMENT ON TABLE orders IS 'One row per order. Cleaned every night.';
COMMENT ON COLUMN orders.revenue IS 'In dollars, after discounts.'Step by step
- COMMENT ON TABLE, the table's name, IS, then the note in single quotes.
COMMENT ON TABLE orders IS 'One row per order. Cleaned every night.'; - COMMENT ON COLUMN uses table.column.
COMMENT ON TABLE orders IS 'One row per order. Cleaned every night.'; COMMENT ON COLUMN orders.revenue IS 'In dollars, after discounts.'; - Say what the data means and how it's cleaned: units, allowed values, who updates it.
COMMENT ON TABLE orders IS 'One row per order. Cleaned every night.'; COMMENT ON COLUMN orders.revenue IS 'In dollars, after discounts.';
Practice
1. Add this comment to the orders table: 'One row per order'.
COMMENT ON TABLE orders IS 'One row per order'2. Add this comment to the revenue column of orders: 'In dollars, after discounts'.
COMMENT ON COLUMN orders.revenue IS 'In dollars, after discounts'3. Add this comment to the orders table: 'Cleaned every night. Duplicates removed.'
COMMENT ON TABLE orders IS 'Cleaned every night. Duplicates removed.'4. Add this comment to the order_date column of orders: 'The day the order was placed'.
COMMENT ON COLUMN orders.order_date IS 'The day the order was placed'5. Add this comment to the category column of orders: 'Allowed: Electronics, Clothing, Home, Beauty'.
COMMENT ON COLUMN orders.category IS 'Allowed: Electronics, Clothing, Home, Beauty'Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →