COMMENT Statement

The COMMENT statement is used to add comments in SQL code, which helps document the database structure and logic. Comments are not executed by the SQL engine and serve only for documentation.

Example: Adding a Comment

-- This table stores information about key freedom fighters
CREATE TABLE FreedomFighters (
    FighterID INT PRIMARY KEY,
    Name VARCHAR(50) NOT NULL,
    Contribution VARCHAR(100),
    BirthDate DATE
);

Code Explanation: The double dash (--) is used for single-line comments in SQL. Comments provide clarity and help others understand the purpose of the code.

Do's and Don'ts

Do's

  • Use comments to explain complex SQL logic or database structures.
  • Keep comments concise and meaningful.
  • Use comments to document the purpose of tables and columns.

Don'ts

  • Don't add unnecessary comments that clutter the code.
  • Don't use comments as a replacement for clear and understandable table and column names.
  • Don't forget to update comments if the related code or table structure changes.