Comments in SQL
? Comments in SQL
Comments allow you to include notes or explanations within your SQL code that are ignored during execution. They help improve readability and maintainability.
? Types of Comments in SQL
1. Single-line comments
Use two hyphens
--Everything after
--on the same line is treated as a comment.
SELECT * FROM employees; -- This fetches all employees2. Multi-line (or block) comments
Enclosed between
/*and*/Can span multiple lines.
/*This query retrieves employeeswith a salary greater than 50000*/SELECT * FROM employees WHERE salary > 50000;? Notes
Comments are ignored by the SQL engine.
Use comments to explain complex queries or temporarily disable parts of SQL code.
Supported by all major SQL databases (MySQL, PostgreSQL, SQL Server, Oracle).
If you want, I can show you examples of commenting out parts of queries or best practices!