0% found this document useful (0 votes)
3 views1 page

SQL Practice Note Book

The document outlines five SQL best practices for effective coding: use uppercase for SQL keywords and functions, single quotes for text strings, follow specific naming conventions for columns and tables, utilize comments for clarity, and maintain clean indentation in code. It emphasizes the importance of consistency in style and provides tips for avoiding common mistakes. Following these guidelines can enhance readability and maintainability of SQL code.

Uploaded by

vg4884726
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

SQL Practice Note Book

The document outlines five SQL best practices for effective coding: use uppercase for SQL keywords and functions, single quotes for text strings, follow specific naming conventions for columns and tables, utilize comments for clarity, and maintain clean indentation in code. It emphasizes the importance of consistency in style and provides tips for avoiding common mistakes. Following these guidelines can enhance readability and maintainability of SQL code.

Uploaded by

vg4884726
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

```

📝 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! 🚀

You might also like