1. SQL kya hai?
Jawaab: SQL ka full form hai "Structured Query Language". Yeh ek aisi language hai jisse hum computer ko bol sakte hain ke database (jaise ek badi kitaab ya register jisme data hota hai) se kuch information nikaale, badle, ya naye data ko store kare. SQL zyada tar database manage karne ke liye use hoti hai, jaise MySQL aur SQL Server.
2. Primary Key kya hoti hai?
Jawaab: Primary Key ek aisa khaas column hota hai jo table ke har record ko unique banata hai, yaani har row alag hoti hai. Yeh key kabhi repeat nahi hoti aur NULL
bhi nahi hoti. Jaise ek class mein har student ka alag roll number hota hai, waise hi Primary Key ek unique ID banati hai.
3. SQL mein Joins kya hote hain? Aur inke types batao.
Jawaab: Joins ka kaam do ya zyada tables ke records ko jodna hota hai. Jaise ek table mein students ke naam hain aur doosri mein unke marks, toh join se dono tables ke data ko ek saath dekh sakte hain.
- INNER JOIN: Sirf wahi rows lata hai jo dono tables mein match karti hain.
- LEFT JOIN: Sab rows left table se lata hai aur right table se matching rows leta hai. Agar match na ho toh
NULL
dikhata hai. - RIGHT JOIN: Sab rows right table se lata hai aur left table se matching rows leta hai. Agar match na ho toh
NULL
dikhata hai. - FULL JOIN: Sab rows lata hai chahe match ho ya nahi, aur match na hone par
NULL
show karta hai.
4. Foreign Key kya hoti hai?
Jawaab: Foreign Key ek column hai jo ek table ke Primary Key ko doosri table mein link karta hai. Yeh do tables ke beech ka rishtey (relationship) ko banata hai. Jaise agar students aur classes ki alag tables hain, toh Foreign Key se students aur classes ka connection bana sakte hain.
5. Self Join kya hota hai?
Jawaab: Self Join mein ek table ko usi table se join karte hain. Jaise ek employees ki table ho jisme har employee ka manager bhi hai, jo khud bhi employee hai. Self Join se hum yeh dekh sakte hain ke kaunsa employee kiske under kaam kar raha hai.
6. WHERE aur HAVING mein kya farq hai?
Jawaab:
- WHERE Clause: Yeh rows ko filter karta hai bina data ko group kiye.
SELECT
,UPDATE
, aurDELETE
ke sath use hota hai. - HAVING Clause: Yeh aggregated records ko filter karta hai, yaani jab data ko group kiya gaya ho. Yeh zyada tar
GROUP BY
ke sath use hota hai.
7. Indexes kya hote hain?
Jawaab: Index ek khaas list hai jo database ko data jaldi dhundhne mein madad karti hai. Jaise kitaab ke pehle page par topics ki list hoti hai, waise hi index se rows jaldi mil jaati hain. Lekin, indexes ko bar-bar update karna padta hai jab data add ya delete hota hai.
8. DELETE aur TRUNCATE mein kya farq hai?
Jawaab:
- DELETE: Specific rows ko delete karta hai jo
WHERE
clause mein di gayi condition ko match karti hain. Yeh slow hai kyunki yeh har row ko individually delete karta hai aur rollback ho sakta hai. - TRUNCATE: Saare rows ko ek saath delete karta hai bina condition ke aur rollback nahi ho sakta. Yeh delete se fast hota hai.
9. SQL mein Aggregate Functions kya hote hain? Kuch examples batao.
Jawaab: Aggregate functions data ko count ya total karne mein madad karte hain. Yeh ek single result dete hain. Kuch common aggregate functions hain:
- COUNT: Rows ko gin leta hai.
- SUM: Column mein values ka total nikalta hai.
- AVG: Column mein values ka average nikalta hai.
- MIN: Column ki minimum value batata hai.
- MAX: Column ki maximum value batata hai.
10. SQL Injection kya hota hai aur ise kaise roka ja sakta hai?
Jawaab: SQL Injection ek tarika hai jisse ek attacker input field mein malicious (nuksan pohchane wala) SQL code daal kar database ka data chura sakta hai ya change kar sakta hai. Isse bachne ke liye:
- Parameterized Queries aur Prepared Statements use karo.
- Dynamic SQL ko avoid karo jo user input ko directly use kar raha ho.
Comments
Post a Comment