← Back to MySQL Course | Chapter 1: Introduction & Basics | Lesson 8 of 8

MySQL Comments

SQL में एक comment किसी book के margin में एक sticky note जैसा है जिसे computer ignore करता है। यह सिर्फ इसलिए है ताकि लोग समझ सकें कि code क्या कर रहा है।
Syntax
sql
-- single-line comment
# MySQL-style single-line comment
/* multi-line
   comment */

Double Dash से Single-Line Comments

एक double-dash (--) एक comment शुरू करता है जो line के अंत तक चलता है, लेकिन standard SQL को dashes के तुरंत बाद एक space चाहिए नहीं तो MySQL इसे बिल्कुल comment नहीं मान सकता।

उदाहरण: Single-Line Comments with Double Dash

sql
-- This is a comment
SELECT 1;

Hash से Single-Line Comments

hash symbol (#) एक MySQL-specific single-line comment marker है जो double-dash जैसा behave करता है लेकिन, इसके उलट, इसे trailing space नहीं चाहिए — दोनों styles के बीच एक छोटा लेकिन आसानी से भूल जाने वाला अंतर।

उदाहरण: Single-Line Comments with Hash

sql
#This is a MySQL-specific comment
SELECT 1;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Multi-Line Comments

Block comments /* से शुरू होते हैं और */ से खत्म होते हैं, और कई lines तक फैल सकते हैं, जो उन्हें किसी complex query के इस तरह structured होने की longer explanations के लिए सही choice बनाता है।

उदाहरण: Multi-Line Comments

sql
/* This is a
   multi-line comment */
SELECT 1;

SQL Statements के अंदर Comments

आप एक block comment को किसी statement के बीच में, किसी column name या clause के ठीक बगल में डाल सकते हैं, आसपास के SQL syntax को तोड़े बिना यह document करने के लिए कि वह हिस्सा exactly क्या करता है।

उदाहरण: Comments inside SQL Statements

sql
SELECT name /* the customer's full name */ FROM customers;

Executable Comments

MySQL एक special executable comment syntax (/*! ... */) support करता है जिसे दूसरे database systems बस एक normal comment मानकर ignore कर देते हैं, आपको MySQL-specific optimizations लिखने देते हुए जो दूसरे engines के लिए portable रहती हैं।

उदाहरण: Executable Comments

sql
SELECT /*! SQL_NO_CACHE */ * FROM customers;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. दो dashes के बाद बिना space के --comment लिखना, जबकि MySQL को एक comment शुरू करने के लिए -- एक space (या control character) के साथ चाहिए।
  2. एक block comment पर closing */ भूल जाना, ताकि script का बाकी हिस्सा comment हो जाए।
  3. किसी ; से पहले एक comment इस तरह रखना कि statement का हिस्सा छुप जाए, जैसे SELECT 1 -- ;।
चैप्टर सारांश
  • MySQL एक relational database management system है जो data को tables में store करता है और इसके साथ काम करने के लिए SQL इस्तेमाल करता है।
  • MySQL install करना और Workbench या command line इस्तेमाल करना आपको SQL statements चलाने देता है।
  • Comments और data types का एक overview MySQL code लिखने के लिए पहले building blocks हैं।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.