पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
SQL में grouping sets किस clause के साथ बताए जाते हैं?
Which clause is used to define grouping sets in SQL?
AGROUP BY
BHAVING
CORDER BY
DGROUP SETS
सही उत्तर / Answer: (A)
हल / Solution
पूरा रूप GROUP BY GROUPING SETS (...) है, यानी grouping sets GROUP BY का ही विस्तार हैं। इनसे एक ही query में कई तरह के समूह एक साथ बन जाते हैं, और ROLLUP तथा CUBE भी इसी जगह लिखे जाते हैं। HAVING बने हुए समूहों को छानता है, ORDER BY नतीजे को छाँटता है, और GROUP SETS नाम का कोई clause SQL में है ही नहीं — वह असली keyword से मिलता-जुलता भटकाव है।
The full form is GROUP BY GROUPING SETS (...), so grouping sets are an extension of GROUP BY itself. They let a single query build several different groupings at once, and ROLLUP and CUBE are written in the same place. HAVING filters groups once they exist, ORDER BY sorts the finished rows, and GROUP SETS is not an SQL clause at all, only a near miss of the real keyword.
प्रश्न 2उत्तर + हल
एक ही SQL query में GROUP BY, HAVING और ORDER BY साथ लिखने का सही क्रम क्या है?
What is the correct order of clauses when using GROUP BY, HAVING, and ORDER BY together in a SQL query?
AGROUP BY, HAVING, ORDER BY
BORDER BY, GROUP BY, HAVING
CHAVING, GROUP BY, ORDER BY
DHAVING, ORDER BY, GROUP BY
सही उत्तर / Answer: (A)
हल / Solution
Query इस क्रम में लिखी जाती है — SELECT, FROM, WHERE, GROUP BY, HAVING और सबसे अंत में ORDER BY। यह क्रम काम के क्रम से निकला है: पहले समूह बनते हैं, फिर बने हुए समूहों पर HAVING की छननी लगती है, और जो बचता है उसे अंत में छाँटा जाता है। इसीलिए ORDER BY को पहले या HAVING को GROUP BY से पहले लिखने पर सीधा syntax error मिलता है।
A query is written as SELECT, FROM, WHERE, GROUP BY, HAVING and then ORDER BY. The order follows the way the work is actually done: rows are grouped first, the finished groups are filtered by HAVING, and whatever survives is sorted last of all. Writing ORDER BY first, or HAVING ahead of GROUP BY, simply gives a syntax error, so the first sequence is the only correct one.
प्रश्न 3उत्तर + हल
COUNT(), SUM() और AVG() जैसे aggregate functions किस clause में इस्तेमाल किए जा सकते हैं?
In which clause can you use aggregate functions such as COUNT(), SUM(), and AVG()?
AWHERE clause
BGROUP BY clause
CFROM clause
DHAVING clause
सही उत्तर / Answer: (D)
हल / Solution
Aggregate function पूरे समूह पर काम करता है, इसलिए उसका मान तभी निकल सकता है जब समूह बन चुके हों। WHERE समूह बनने से पहले चलता है, इसलिए वहाँ COUNT या SUM लिखने पर error मिलता है। GROUP BY में सिर्फ़ वे column आते हैं जिन पर समूह बनाना है, और FROM में table या subquery का नाम आता है। बने हुए समूहों को छानने वाला HAVING ही है, और वहीं ये functions चलते हैं।
An aggregate function works on a whole group, so its value can be computed only once the groups exist. WHERE runs before grouping, which is why COUNT or SUM there raises an error. GROUP BY lists just the columns to group by, and FROM names a table or a subquery. HAVING is the clause that filters the finished groups, and that is where these functions properly belong.
प्रश्न 4उत्तर + हल
SQL में नतीजे को एक से ज़्यादा columns के आधार पर कैसे छाँटा (sort) जाता है?
How can you sort the result set by multiple columns in SQL?
AORDER BY में सिर्फ़ एक column लिखकरBy using the ORDER BY clause with only one column
BORDER BY में अल्पविराम से अलग किए कई columns लिखकरBy using the ORDER BY clause with multiple columns separated by commas
CGROUP BY clause लगाकरBy using the GROUP BY clause
DHAVING clause लगाकरBy using the HAVING clause
सही उत्तर / Answer: (B)
हल / Solution
ORDER BY में जितने column चाहिए, अल्पविराम से अलग करके लिखे जा सकते हैं। छँटाई बाएँ से दाएँ होती है — पहले column पर, और उसमें बराबरी निकले तो अगले column पर, और इसी तरह आगे। हर column के साथ अपना ASC या DESC भी लग सकता है। एक column से सिर्फ़ एक स्तर मिलेगा; GROUP BY समूह बनाता है और HAVING समूह छानता है, छाँटना इन दोनों का काम नहीं।
ORDER BY accepts as many columns as you need, separated by commas. Sorting then works from left to right: rows are ordered by the first column, ties are broken by the next one, and so on down the list. Each column may carry its own ASC or DESC. One column gives only one level of sorting, while GROUP BY builds groups and HAVING filters them, so neither of those sorts anything.
प्रश्न 5उत्तर + हल
ORDER BY clause का सही उपयोग कौन-सा कथन दिखाता है?
Which statement correctly demonstrates the usage of the ORDER BY clause?
ASELECT * FROM table_name ORDER BY column1, column2 DESC;
BSELECT * FROM table_name ORDER BY column2 WHERE column1 = value;
CSELECT * FROM table_name GROUP BY column1 ORDER BY column2;
DSELECT column1, COUNT(*) FROM table_name ORDER BY column1 DESC;
सही उत्तर / Answer: (A)
हल / Solution
ORDER BY query के सबसे अंत में आता है और उसमें अल्पविराम से कई column लिखे जा सकते हैं, हर एक का अपना ASC या DESC भी। इसलिए पहला कथन ही सही है। दूसरे में WHERE को ORDER BY के बाद रखा गया है, जो syntax error देता है। तीसरे में GROUP BY के साथ सारे column माँगे गए हैं और छँटाई समूह से बाहर के column पर है। चौथे में COUNT(*) है पर GROUP BY नहीं।
ORDER BY always comes last in a query, and it may list several columns separated by commas, each with its own ASC or DESC. So the first statement is the correct one. The second puts WHERE after ORDER BY, which the parser rejects outright. The third asks for every column while grouping by one and sorting by another. The fourth uses COUNT(*) beside a plain column with no GROUP BY, so it fails too.
प्रश्न 6उत्तर + हल
SQL में HAVING clause कब इस्तेमाल करना चाहिए?
When should you use the HAVING clause in SQL?
Aनतीजे की पंक्तियों का क्रम तय करने के लिएTo specify the order of rows in the result set
Bसमूहों (groups) को उनके aggregate मानों के आधार पर छानने के लिएTo filter groups based on aggregated values
Cकई tables को जोड़ने के लिएTo join multiple tables
Dcolumns पर गणित की क्रियाएँ करने के लिएTo perform arithmetic operations on columns
सही उत्तर / Answer: (B)
हल / Solution
WHERE पंक्ति-दर-पंक्ति छानता है और GROUP BY से पहले चलता है, इसलिए उसमें SUM या COUNT लिखे ही नहीं जा सकते। समूह बन जाने के बाद उन्हीं समूहों को उनके aggregate मान से छानने के लिए HAVING है — जैसे HAVING COUNT(*) > 5। पंक्तियों का क्रम ORDER BY तय करता है, tables JOIN से जुड़ते हैं, और गणित की साधारण क्रियाएँ SELECT की सूची में ही हो जाती हैं।
WHERE works row by row and runs before grouping, so SUM or COUNT cannot appear in it at all. HAVING comes after GROUP BY has built the groups, so it filters whole groups by their aggregate values, as in HAVING COUNT(*) > 5. Sorting is the job of ORDER BY, tables are joined with JOIN, and ordinary arithmetic on columns can sit in the SELECT list itself.
प्रश्न 7उत्तर + हल
SQL में trigger को debug कैसे किया जा सकता है?
How can you debug triggers in SQL?
Atrigger के code में debug संदेश छापकरBy printing debug messages in the trigger code
Bdatabase management system (DBMS) के debugging tools इस्तेमाल न करकेBy not using debugging tools provided by the database management system
Ctrigger को कुछ समय के लिए बंद करकेBy temporarily disabling triggers
Ddatabase में trigger का code सीधे बदलकरBy modifying the trigger code directly in the database
सही उत्तर / Answer: (A)
हल / Solution
Trigger नज़र से छिपकर चलता है, इसलिए उसे debug करने का चलता हुआ तरीक़ा यही है कि उसे बुलवा लिया जाए — भीतर के मान किसी log table में लिखिए या जाँच के समय संदेश छपवाइए। विकल्प 2 ख़ुद अपनी बात काटता है। trigger बंद करने से इतना ही पता चलता है कि गड़बड़ उसी की है, भीतर का हाल नहीं दिखता; और code सीधे बदलना मरम्मत है, जाँच नहीं।
A trigger runs out of sight, so the practical way to debug one is to make it talk: write the values it sees into a log table, or print messages while testing. Option 2 contradicts itself by refusing the very tools the server offers. Turning the trigger off shows only whether it is the culprit and says nothing about its logic, while editing the code is a repair step rather than a way of finding the fault.
प्रश्न 8उत्तर + हल
SQL में trigger बनाते समय कौन-सी आदत अच्छी मानी जाती है?
What is a best practice when designing triggers in SQL?
Atrigger को सरल रखना और एक ही निश्चित काम तक सीमित रखनाKeep triggers simple and focused on a specific task
Bजटिल business logic trigger के भीतर ही रखनाUse triggers to handle complex business logic
Cअस्थायी (temporary) tables पर trigger बनानाCreate triggers on temporary tables
Dबिना किसी साफ़ मक़सद के trigger बनानाDefine triggers with no specific purpose
सही उत्तर / Answer: (A)
हल / Solution
Trigger किसी और के transaction के भीतर, नज़र से छिपकर चलता है। इसलिए उसे छोटा और एक ही काम तक सीमित रखा जाता है — तब lock देर तक नहीं टिकते और गड़बड़ ढूँढ़ना आसान रहता है। भारी business logic stored procedure या application में अच्छा रहता है, जहाँ उसे बुलाया और जाँचा जा सकता है। MySQL में temporary table पर trigger बनता ही नहीं, और बिना मक़सद वाला trigger सिर्फ़ ख़र्च है।
Good trigger design keeps each trigger short and tied to one clear job. A trigger fires invisibly inside somebody else's transaction, so long code holds locks for longer and is hard to debug afterwards. Heavy business logic belongs in a stored procedure or in the application, where it can be called and tested openly. MySQL does not even allow triggers on temporary tables, and an aimless trigger is pure cost.
प्रश्न 9उत्तर + हल
SQL में trigger किस हाल में transaction को rollback करा देता है?
In which scenario would a trigger cause a transaction rollback in SQL?
Aजब trigger चलते समय कोई error आ जाएWhen an error occurs during trigger execution
Bजब trigger कई tables का data बदलेWhen a trigger modifies data in multiple tables
Cजब trigger बंद (disabled) कर दिया गया होWhen a trigger is disabled
Dजब trigger AFTER trigger के रूप में बनाया गया होWhen a trigger is defined as an AFTER trigger
सही उत्तर / Answer: (A)
हल / Solution
Trigger उसी transaction के भीतर चलता है जिसने उसे चलाया, अलग से नहीं। इसलिए उसमें error आ जाए, या SIGNAL से जान-बूझकर अपवाद उठाया जाए, तो वह statement नाकाम होता है और अब तक का काम rollback हो जाता है — यही शर्तें लागू कराने का तरीक़ा भी है। कई tables बदलना रोज़ का काम है, बंद trigger चलता ही नहीं, और AFTER होना सिर्फ़ समय बताता है।
A trigger runs inside the transaction that fired it, not beside it. So if its code hits an error, or raises one on purpose with SIGNAL, the statement fails and the work done so far is rolled back; this is in fact how triggers enforce rules. Changing several tables is normal trigger work, a disabled trigger never runs at all, and being an AFTER trigger only says when it fires.
प्रश्न 10उत्तर + हल
डेटा अखंडता (data integrity) की शर्तें लागू करने के लिए trigger का एक विकल्प क्या है?
What is an alternative to using triggers for enforcing data integrity constraints?
APrimary keys
BCursors
CDatabase backups
DTable partitioning
सही उत्तर / Answer: (A)
हल / Solution
बहुत सी शर्तें trigger लिखे बिना, घोषित (declarative) रूप में ही लग जाती हैं। Primary key ऐसी ही शर्त है — वह हर पंक्ति को अनोखा रखती है और उस column को NULL होने से रोकती है, और यह जाँच हर insert तथा update पर database ख़ुद करता है। Cursor पंक्तियाँ एक-एक करके पढ़ने का औज़ार है, backup सुरक्षा का इंतज़ाम है और partitioning रफ़्तार का — इनमें से कोई शर्त लागू नहीं करता।
Many rules can be stated once and then left to the database, with no trigger code at all. A primary key is such a rule: it keeps every row uniquely identifiable and stops that column from being NULL, and the server checks it on every insert and update. A cursor only walks through rows one by one, a backup protects data, and partitioning splits a large table for speed. None of them enforces a rule.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति