```
📝 SQL Best Practices
The Ultimate Pro-Guide (Easy Hinglish Edition) 🚀
🌟 SQL Rules 🌟
👇
🔠 1. Capitalization 💬 2. Quotes (' vs ") 🏷️ 3. Naming Rules 📝 4. Comments
📏 5. Indentation
🔠 1. Capitalization (Bade & Chhote Akshar)
Waise toh SQL me uppercase ya lowercase likhne se koi error nahi aata. Aap SELECT likho ya
select, SQL sab samajh jata hai.
But Pro-Coders humesha ek FIX style follow karte hain!
Pro Style Rule:
📌 Clause / Keywords: Humesha ALL CAPS me likho (e.g., SELECT, FROM, WHERE).
📌 Functions: Humesha ALL CAPS me (e.g., SUM(), COUNT()).
📌 Column Names: Humesha lowercase me likho (e.g., total_tickets).
📌 Table Names: Humesha CamelCase me likho (e.g., FavoriteFoods).
🧠 Memory Trick: KFC Rule
Keywords & Functions = CAPS me.
Columns = chote (lowercase) me.
❌ Common Mistake - Dialects (SQL Variants):
Zyadatar SQL (jaise MySQL) strings me case ignore karte hain ('us' aur 'US' same hai).
Lekin BigQuery aur Vertica jaise dialects Case-Sensitive hote hain! Wahan 'us' aur 'US'
alag alag hain.
💬 2. Single (') vs Double (") Quotes
Bohot bache isme confuse hote hain. Simple sa rule yaad rakho:
👉 General rule ye hai ki humesha Text Strings ke liye Single Quotes (' ') ka use karo.
✅ Right Way (Single) ❌ Wrong Way (Double)
SELECT * FROM Users WHERE country SELECT * FROM Users WHERE country
= 'US' = "US" -- Zyadatar SQL dialect me
ignore hoga par ideal nahi!
Q: Toh Double Quotes (") kab use karein? 🤔
Jab aapke text (string) ke andar pehle se hi ek apostrophe (') ho, tab double quotes lagana
padta hai, warna SQL confuse ho jayega.
🎯 Exam Point / Real World Use:
Agar string hai: Shepherd's pie
Galat (Error): Favorite_food = 'Shepherd's pie' (SQL sochega string
'Shepherd' par khatam ho gayi!)
Sahi: Favorite_food = "Shepherd's pie" (Yaha " " bahar lagaya taaki andar ka
' safe rahe).
🏷️ 3. Naming Rules (Naamkaran)
Jab bhi koi naya column calculate karte hain, SQL default naam deta hai jaise f0, f1, f2.
Isko AS laga kar hamesha rename karo!
Aur haan, NAMING MEIN SPACE KABHI MAT DENA! (Space = Dushmani 😡)
Kya Naming karni hai? Kaise karni hai? Example
Columns (Cols) snake_case (Use underscores `_`) total_tickets, first_name
Tables CamelCase (Start word capital) TicketsByOccasion, Users
⚡ Shortcut Tip:
Bada naam ho? Spaces ki jagah Underscore ( _ ) laga do! Jaise: number of rows
number_of_rows
➡️
📝 4. Comments (Apni Yaad-daasht ke liye)
Comments code ka wo hissa hain jo Computer padhta hi nahi hai! Ye sirf aapke aur aapki team
ke doston ke samajhne ke liye hota hai.
👉 1 Line wala Comment: -- ya # use karo. (Par -- zyada standard hai, har SQL me chalta
hai).
👉 Bohot saari lines (Multi-line): /* se shuru karo aur */ pe khatam karo.
/* Date: June 28, 2026 Goal: Dono tables ko join karna hai */ SELECT
COUNT(*) AS total_rows -- Yaha se total ginte hain FROM FavoriteFoods
📏 5. Indentation & Text Editors
Gich-pich code likhna ek bad habit hai! Apne code ko clean aur readable banayein.
📏 Rule of Thumb: Ek line me Maximum 100 Characters hi rakho.
🔄 Nayi line me code tod (break) do. (Jaise har keyword SELECT, FROM, WHERE ke baad
nayi line lo).
💻 Tools: SQL likhne ke liye normal notepad mat use karo. Sublime Text ya Atom jaise
color-coded text editors use karo!
💻 Sublime Text Pro-Tip:
Bohot saari lines ko ek saath aage-peeche (Indent) karna hai?
Sari lines select karo aur Cmd/Ctrl + [ dabao (piche laane ke liye).
Cmd/Ctrl + ] dabao (aage badhane ke liye).
🎉 Bss! Ye 5 rules follow karo aur tum SQL Master ban jaoge! Keep Coding! 🚀