MySQL Test 2 – SQL Commands (50 Marks)
MySQL Test 2 – SQL Commands (50 Marks) Hindi Instructions
MySQL Test 2 – SQL Commands (50 Marks)
Question Palette
Green = answered, Purple = review, White = not answered.
उत्तर कुंजी और व्याख्या
पहले test पूरा करें और submit करें, फिर अपने उत्तर यहाँ मिलाएँ। हर उत्तर के साथ छोटा explanation है ताकि ग़लती का कारण समझ आए।
सभी 50 उत्तर दिखाएँ
- Which command creates a new database named school?
उत्तर: D. CREATE DATABASE school; – CREATE DATABASE creates it; USE school; selects it.
- Which command selects a database for use?
उत्तर: C. USE school; – After USE, all table names refer to that database.
- Which command shows all tables of the current database?
उत्तर: B. SHOW TABLES; – SHOW DATABASES lists databases; SHOW TABLES lists tables.
- Which command shows the structure (columns and types) of a table?
उत्तर: D. DESCRIBE students; – DESC students; is the short form.
- Which data type is best for a name of up to 50 characters?
उत्तर: A. VARCHAR(50) – VARCHAR stores variable-length text up to the given length.
- Which data type stores exact money values like 1250.75?
उत्तर: A. DECIMAL(10,2) – DECIMAL avoids floating-point rounding errors in money calculations.
- The default date format in MySQL is:
उत्तर: C. YYYY-MM-DD – Example: '2026-03-15'.
- Which statement adds a new row to a table?
उत्तर: A. INSERT INTO students VALUES (1, 'Asha', 88); – INSERT INTO table [(columns)] VALUES (...).
- Which statement changes Asha's marks to 92?
उत्तर: B. UPDATE students SET marks = 92 WHERE name = 'Asha'; – Always use WHERE with UPDATE, otherwise every row changes.
- What happens if you run UPDATE students SET marks = 0; without WHERE?
उत्तर: C. Marks of every student become 0 – UPDATE without WHERE affects all rows – a common costly mistake. MySQL Workbench's safe-update mode blocks it.
- Which statement deletes all students of class 9 but keeps the table?
उत्तर: D. DELETE FROM students WHERE class = 9; – DELETE removes rows; DROP removes the whole table; TRUNCATE has no WHERE.
- Difference between DELETE (without WHERE) and TRUNCATE:
उत्तर: C. TRUNCATE is DDL, faster and resets AUTO_INCREMENT – Both empty the table, but TRUNCATE recreates it and cannot be filtered.
- Which command removes a table and its structure permanently?
उत्तर: A. DROP TABLE students; – After DROP, the table no longer exists.
- Which command adds a column email to students?
उत्तर: A. ALTER TABLE students ADD email VARCHAR(80); – ALTER TABLE … ADD / MODIFY / DROP / RENAME COLUMN changes structure.
- Which command changes the data type of column marks to DECIMAL(5,2)?
उत्तर: B. ALTER TABLE students MODIFY marks DECIMAL(5,2); – MODIFY changes the definition; CHANGE can also rename the column.
- Which query shows only the name and marks columns?
उत्तर: A. SELECT name, marks FROM students; – List the columns after SELECT, separated by commas.
- Which keyword removes duplicate values from the result?
उत्तर: A. DISTINCT – SELECT DISTINCT city FROM students; lists each city once.
- Which clause sorts the result by marks, highest first?
उत्तर: A. ORDER BY marks DESC – ASC is the default; DESC gives descending order.
- Which condition finds names starting with 'A'?
उत्तर: A. name LIKE 'A%' – % matches any number of characters; _ matches exactly one.
- Which condition finds names whose second letter is 'a'?
उत्तर: B. name LIKE '_a%' – The _ stands for exactly one character before 'a'.
- Which query finds students with marks from 60 to 80 inclusive?
उत्तर: B. WHERE marks BETWEEN 60 AND 80 – BETWEEN includes both end values.
- Which condition selects students from Delhi, Pune or Jaipur?
उत्तर: A. city IN ('Delhi', 'Pune', 'Jaipur') – IN is a short form of several OR conditions.
- How do you find rows where phone is missing?
उत्तर: A. WHERE phone IS NULL – NULL is not equal to anything, even NULL; always use IS NULL / IS NOT NULL.
- What does SELECT COUNT(*) FROM students; return?
उत्तर: B. The number of rows in students – COUNT(*) counts rows including those with NULLs.
- COUNT(phone) counts:
उत्तर: A. Rows where phone is not NULL – Aggregate functions on a column ignore NULLs.
- Which function returns the average marks?
उत्तर: D. AVG(marks) – Other aggregates: SUM, MIN, MAX, COUNT.
- Which clause groups rows to show average marks per class?
उत्तर: B. GROUP BY class – SELECT class, AVG(marks) FROM students GROUP BY class;
- To show only classes whose average marks are above 75, use:
उत्तर: D. HAVING AVG(marks) > 75 – WHERE filters rows before grouping; HAVING filters groups after aggregation.
- Correct order of clauses in a SELECT statement:
उत्तर: B. SELECT – FROM – WHERE – GROUP BY – HAVING – ORDER BY – LIMIT – Writing them in this order avoids syntax errors.
- Which query returns the top 3 scorers?
उत्तर: D. SELECT * FROM students ORDER BY marks DESC LIMIT 3; – MySQL uses LIMIT; SQL Server uses TOP.
- What does SELECT ROUND(78.456, 1); return?
उत्तर: C. 78.5 – ROUND(x, d) rounds to d decimal places.
- What does SELECT UPPER('sql'); return?
उत्तर: D. SQL – UPPER/UCASE converts to capitals; LOWER/LCASE to small letters.
- What does SELECT LENGTH('India'); return?
उत्तर: D. 5 – LENGTH returns bytes; for plain English letters that equals the number of characters. Use CHAR_LENGTH for Hindi text.
- What does SELECT SUBSTR('Database', 1, 4); return?
उत्तर: C. Data – SUBSTR(string, start, length); positions start at 1.
- What does SELECT CONCAT('Coding', 'Easily'); return?
उत्तर: D. CodingEasily – CONCAT joins strings without adding spaces.
- What does SELECT MOD(17, 5); return?
उत्तर: D. 2 – MOD returns the remainder: 17 = 5×3 + 2.
- Which function returns today's date?
उत्तर: B. CURDATE() – NOW() returns date and time; CURDATE() returns only the date.
- What does SELECT YEAR('2026-08-15'); return?
उत्तर: B. 2026 – MONTH() and DAY() extract the other parts.
- What does SELECT POWER(2, 5); return?
उत्तर: D. 32 – POWER(x, y) = x raised to y.
- Which gives an alias to a column in the result?
उत्तर: C. SELECT marks AS score FROM students; – AS renames a column or table only in that query's output.
- Which command gives user 'ravi' permission to read the school database?
उत्तर: D. GRANT SELECT ON school.* TO 'ravi'@'localhost'; – REVOKE … FROM removes the permission.
- After START TRANSACTION, which command undoes uncommitted changes?
उत्तर: A. ROLLBACK; – ROLLBACK cancels all changes since the transaction started (or since a SAVEPOINT).
- Which statement inserts several rows at once?
उत्तर: D. INSERT INTO t (a,b) VALUES (1,2), (3,4), (5,6); – Separate each row's values with commas – faster than many single inserts.
- Which constraint automatically gives the next number to a new row's id?
उत्तर: D. AUTO_INCREMENT – Usually: id INT AUTO_INCREMENT PRIMARY KEY.
- Which clause in CREATE TABLE sets a value when none is given?
उत्तर: B. DEFAULT – Example: city VARCHAR(30) DEFAULT 'Delhi'.
- Which command renames table students to learners?
उत्तर: D. RENAME TABLE students TO learners; – ALTER TABLE students RENAME TO learners; also works.
- Which query counts students in each city?
उत्तर: D. SELECT city, COUNT(*) FROM students GROUP BY city; – GROUP BY makes one row per city; COUNT(*) counts rows in each group.
- What is the result of NULL + 10 in SQL?
उत्तर: A. NULL – Any arithmetic with NULL gives NULL; use IFNULL(col, 0) or COALESCE to replace it.
- Which function replaces NULL marks with 0 in the output?
उत्तर: A. IFNULL(marks, 0) – COALESCE(marks, 0) is the standard SQL equivalent.
- Which statement saves all changes of the current transaction permanently?
उत्तर: A. COMMIT; – With autocommit ON, each statement is committed automatically.
