{"id":3900,"date":"2025-06-06T19:01:51","date_gmt":"2025-06-06T19:01:51","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3900"},"modified":"2025-06-07T09:54:09","modified_gmt":"2025-06-07T09:54:09","slug":"sql-comments","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-comments\/","title":{"rendered":"SQL Comments"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Comments are notes or explanations you add inside your SQL code to make it easier to understand \u2014 both for yourself and others reading your queries later. They don\u2019t affect how the SQL runs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u270d\ufe0f Why Use Comments?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Explain complex queries<\/strong><\/li>\n\n\n\n<li><strong>Temporarily disable code<\/strong> during debugging<\/li>\n\n\n\n<li><strong>Document assumptions or reminders<\/strong><\/li>\n\n\n\n<li><strong>Improve code maintainability<\/strong> when working in teams<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0\ufe0f How to Write Comments in SQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are two main ways to add comments:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Single-line Comments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start with two hyphens (<code>--<\/code>)<br>Everything after <code>--<\/code> on that line is a comment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT * FROM employees;  -- Get all employee records<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Multi-line (Block) Comments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enclosed between <code>\/*<\/code> and <code>*\/<\/code><br>Can span multiple lines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>\/*\n  This query fetches all employees\n  whose salary is above 50000\n*\/\nSELECT * FROM employees WHERE salary &gt; 50000;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Tips for Using Comments<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use comments to clarify <strong>why<\/strong> you wrote something, not <strong>what<\/strong> the code does (the code itself should be clear).<\/li>\n\n\n\n<li>Avoid excessive commenting \u2014 keep comments relevant and concise.<\/li>\n\n\n\n<li>Remove or update comments when the code changes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Comment Type<\/th><th>Syntax<\/th><th>Use Case<\/th><\/tr><\/thead><tbody><tr><td>Single-line<\/td><td><code>-- Comment<\/code><\/td><td>Quick notes, short explanations<\/td><\/tr><tr><td>Multi-line<\/td><td><code>\/* Comment *\/<\/code><\/td><td>Longer descriptions, blocks<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Comments are notes or explanations you add inside your SQL code to make it easier to understand \u2014 both for yourself and others reading your queries later. They don\u2019t affect how the SQL runs. \u270d\ufe0f Why Use Comments? \ud83d\udee0\ufe0f How to Write Comments in SQL There are two main ways to add comments: 1. Single-line [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3900","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}