0% found this document useful (0 votes)
4 views17 pages

SQL

Uploaded by

Pravallika Reddy
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)
4 views17 pages

SQL

Uploaded by

Pravallika Reddy
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
You are on page 1/ 17

SQL

🔹 SQL Basics MCQs (1–20)


1. Which SQL keyword is used to retrieve data?
A. GET
B. SELECT
C. FETCH
D. RETRIEVE
Answer: B. SELECT
2. Which SQL clause is used to filter records?
A. SELECT
B. ORDER BY
C. WHERE
D. GROUP BY
Answer: C. WHERE
3. Which SQL command is used to remove a table from a database?
A. DELETE
B. REMOVE
C. DROP
D. ERASE
Answer: C. DROP
4. Which of the following is a DDL command?
A. INSERT
B. SELECT
C. CREATE
D. UPDATE
Answer: C. CREATE
5. The SQL statement to remove duplicate rows is:
A. SELECT UNIQUE
B. SELECT DISTINCT
C. SELECT DIFFERENT
D. SELECT NO_DUPLICATE
Answer: B. SELECT DISTINCT
6. What does SQL stand for?
A. Structured Query Language
B. Simple Query Language
C. Standard Question Language
D. Sequential Query Language
Answer: A. Structured Query Language
7. Which command is used to update data in a table?
A. MODIFY
B. UPDATE
C. CHANGE
D. ALTER
Answer: B. UPDATE
8. Which SQL clause is used to sort the result-set?
A. SORT
B. ORDER BY
C. GROUP BY
D. RANK
Answer: B. ORDER BY
9. To select all columns from a table, use:
A. SELECT all
B. SELECT *
C. SELECT #
D. SELECT ALLCOLUMNS
Answer: B. SELECT *
10. The wildcard character in SQL for a single character is:
A. *
B. %
C. _
D. ?
Answer: C. _
11. Which operator is used to compare a value to a list of literal values?
A. BETWEEN
B. IN
C. LIKE
D. EXISTS
Answer: B. IN
12. Which function returns the number of rows?
A. COUNT()
B. SUM()
C. LENGTH()
D. AVG()
Answer: A. COUNT()
13. Which clause groups rows with the same values?
A. ORDER BY
B. GROUP BY
C. HAVING
D. JOIN
Answer: B. GROUP BY
14. Which SQL command removes all rows from a table but keeps the structure?
A. DELETE
B. DROP
C. TRUNCATE
D. REMOVE
Answer: C. TRUNCATE
15. Which of the following is a DML command?
A. CREATE
B. INSERT
C. DROP
D. ALTER
Answer: B. INSERT
16. Which SQL clause is used with aggregate functions?
A. WHERE
B. HAVING
C. GROUP
D. ORDER
Answer: B. HAVING
17. Which of the following is not a valid aggregate function?
A. COUNT
B. MAX
C. LENGTH
D. AVG
Answer: C. LENGTH
18. The JOIN that returns all records when there is a match in either table is:
A. INNER JOIN
B. FULL JOIN
C. LEFT JOIN
D. RIGHT JOIN
Answer: B. FULL JOIN
19. Which command is used to delete data from a table?
A. REMOVE
B. ERASE
C. DELETE
D. TRUNCATE
Answer: C. DELETE
20. Which of these will return the current date in SQL Server?
A. GETDATE()
B. CURRENT()
C. SYSDATE
D. NOWDATE()
Answer: A. GETDATE()

Would you like me to continue with the next set (21–40)?

You said:
yes provide some query mcqs also
ChatGPT said:

Perfect! Let's now continue with the next set of 20 MCQs (21–40) including SQL queries,
especially those involving SELECT, WHERE, JOIN, GROUP BY, HAVING, subqueries, etc.

🔹 Intermediate SQL & Query-Based MCQs (21–40)


21. What is the output of the query:
SELECT LENGTH('EVERTZ');

A. 5
B. 6
C. 7
D. Error
Answer: B. 6

22. Which query returns employees with salary greater than 50000?
A. SELECT * FROM employees WHERE salary < 50000;
B. SELECT * FROM employees WHERE salary = 50000;
C. SELECT * FROM employees WHERE salary > 50000;
D. SELECT * FROM employees WHERE salary >= 50000;
Answer: C. SELECT * FROM employees WHERE salary > 50000;

23. What does this query return?


SELECT COUNT(*) FROM customers;

A. Number of customers
B. Sum of customers
C. Total columns
D. None
Answer: A. Number of customers

24. Which SQL query selects unique department values from "employees" table?
A. SELECT ALL department FROM employees;
B. SELECT DISTINCT department FROM employees;
C. SELECT UNIQUE department FROM employees;
D. SELECT DIFFERENT department FROM employees;
Answer: B. SELECT DISTINCT department FROM employees;

25. Which query returns names that start with "A"?


A. SELECT name FROM students WHERE name LIKE '%A';
B. SELECT name FROM students WHERE name LIKE 'A%';
C. SELECT name FROM students WHERE name LIKE '_A%';
D. SELECT name FROM students WHERE name = 'A%';
Answer: B. SELECT name FROM students WHERE name LIKE 'A%';

26. Which of the following is correct syntax for INNER JOIN?


A. SELECT * FROM A, B;
B. SELECT * FROM A JOIN B;
C. SELECT * FROM A INNER JOIN B ON A.id = B.id;
D. SELECT * FROM A OUTER JOIN B;
Answer: C. SELECT * FROM A INNER JOIN B ON A.id = B.id;

27. What does this SQL return?


SELECT MAX(salary) FROM employees;

A. Minimum salary
B. Average salary
C. Highest salary
D. Total salary
Answer: C. Highest salary

28. Which SQL command is used to create a new table?


A. MAKE TABLE
B. NEW TABLE
C. CREATE TABLE
D. ADD TABLE
Answer: C. CREATE TABLE
29. Which query finds employees hired in 2024?
A. SELECT * FROM employees WHERE hire_date = '2024';
B. SELECT * FROM employees WHERE hire_date LIKE '2024%';
C. SELECT * FROM employees WHERE hire_date = 2024;
D. SELECT * FROM employees WHERE YEAR(hire_date) = 2024;
Answer: D. SELECT * FROM employees WHERE YEAR(hire_date) = 2024;

30. What does the following SQL do?


SELECT name, COUNT(*) FROM employees GROUP BY name;

A. Counts unique employees


B. Groups and counts each employee name
C. Displays names only
D. Error
Answer: B. Groups and counts each employee name

31. Which SQL query returns the 2nd highest salary from a table?
A. SELECT MAX(salary) FROM employees;
B. SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary)
FROM employees);
C. SELECT TOP 2 salary FROM employees;
D. SELECT SECOND(salary) FROM employees;
Answer: B. SELECT MAX(salary) FROM employees WHERE salary < (SELECT
MAX(salary) FROM employees);

32. What is the result of this query?


SELECT 10 / 2 FROM dual;

A. 5
B. 10
C. 0
D. Error
Answer: A. 5
33. Which query displays all rows where age is between 18 and 25 (inclusive)?
A. SELECT * FROM users WHERE age IN (18,25);
B. SELECT * FROM users WHERE age > 18 AND age < 25;
C. SELECT * FROM users WHERE age BETWEEN 18 AND 25;
D. SELECT * FROM users WHERE age = 18 TO 25;
Answer: C. SELECT * FROM users WHERE age BETWEEN 18 AND 25;

34. Which function gives the total sum of a numeric column?


A. COUNT()
B. SUM()
C. ADD()
D. TOTAL()
Answer: B. SUM()

35. Which of these is used to rename a column in a result set?


A. SELECT name AS employee_name FROM emp;
B. SELECT name = employee_name FROM emp;
C. RENAME name TO employee_name;
D. CHANGE name employee_name;
Answer: A. SELECT name AS employee_name FROM emp;

36. Which query finds names ending with “n”?


A. SELECT name FROM table WHERE name LIKE 'n%';
B. SELECT name FROM table WHERE name LIKE '%n';
C. SELECT name FROM table WHERE name LIKE '_n';
D. SELECT name FROM table WHERE name = '%n';
Answer: B. SELECT name FROM table WHERE name LIKE '%n';
37. Which SQL command is used to modify a table structure?
A. MODIFY
B. CHANGE
C. ALTER
D. UPDATE
Answer: C. ALTER

38. Which query counts how many employees each department has?
A. SELECT COUNT(*) FROM employees;
B. SELECT department FROM employees;
C. SELECT department, COUNT(*) FROM employees GROUP BY department;
D. SELECT COUNT(department) FROM employees;
Answer: C. SELECT department, COUNT(*) FROM employees GROUP BY
department;

39. What will be the output of this SQL?


SELECT NULL + 5;

A. 5
B. NULL
C. 0
D. Error
Answer: B. NULL

40. Which function is used to find the smallest value in a column?


A. SMALL()
B. LEAST()
C. MIN()
D. LOWEST()
Answer: C. MIN()
Would you like me to continue with questions 41–60, focusing more on joins, subqueries,
indexing, constraints, and real-world logic-based queries?

You said:
yes
ChatGPT said:

Great! Here's the next set of 20 SQL MCQs (41–60) focusing on JOINS, subqueries,
constraints, indexes, and logic-based queries, useful for your Evertz placement exam:

🔹 SQL Joins, Subqueries, Constraints MCQs (41–60)


41. Which SQL clause is used to combine rows from two or more tables?
A. MERGE
B. JOIN
C. COMBINE
D. CONNECT
Answer: B. JOIN

42. What does an INNER JOIN return?


A. All rows from both tables
B. Rows with matching values in both tables
C. Only unmatched rows
D. All rows from the left table
Answer: B. Rows with matching values in both tables

43. Which SQL JOIN returns all rows from the left table and matched rows from the right?
A. LEFT JOIN
B. RIGHT JOIN
C. INNER JOIN
D. OUTER JOIN
Answer: A. LEFT JOIN
44. Which JOIN returns all rows when there is a match in one of the tables?
A. FULL JOIN
B. LEFT JOIN
C. CROSS JOIN
D. INNER JOIN
Answer: A. FULL JOIN

45. What does a CROSS JOIN produce?


A. Only matching rows
B. Cartesian product
C. Rows with NULL values
D. Error if no match
Answer: B. Cartesian product

46. Which operator is used to test for the existence of rows in a subquery?
A. EXISTS
B. IN
C. HAS
D. CONTAINS
Answer: A. EXISTS

47. Which of the following is a correlated subquery?


A. A subquery that depends on the outer query
B. A subquery that runs independently
C. A subquery that returns multiple rows
D. A query with no WHERE clause
Answer: A. A subquery that depends on the outer query
48. Which of these is a valid constraint in SQL?
A. NOT EXISTS
B. UNIQUE
C. LIKE
D. LIMIT
Answer: B. UNIQUE

49. Which constraint ensures no duplicate values in a column?


A. PRIMARY KEY
B. NOT NULL
C. DEFAULT
D. FOREIGN KEY
Answer: A. PRIMARY KEY

50. What is the purpose of a FOREIGN KEY?


A. To create a temporary column
B. To enforce referential integrity between tables
C. To prevent NULL values
D. To sort data
Answer: B. To enforce referential integrity between tables

51. Which SQL keyword adds a constraint after a table is created?


A. MODIFY
B. ALTER
C. ADD
D. CHANGE
Answer: B. ALTER

52. What will this query do?


SELECT * FROM employees WHERE department_id IN (SELECT department_id FROM
departments WHERE location = 'Delhi');

A. Return all employees


B. Return employees from Delhi departments
C. Return Delhi location only
D. Error
Answer: B. Return employees from Delhi departments

53. Which function is used to find the remainder of a division?


A. MOD()
B. REMAINDER()
C. DIVIDE()
D. FLOOR()
Answer: A. MOD()

54. Which clause is used to restrict group rows after grouping?


A. WHERE
B. HAVING
C. LIMIT
D. RESTRICT
Answer: B. HAVING

55. Which of the following is NOT a valid SQL constraint?


A. PRIMARY KEY
B. NOT NULL
C. FOREIGN KEY
D. SORT BY
Answer: D. SORT BY
56. What is the result of this SQL?
SELECT COUNT(DISTINCT department) FROM employees;

A. Total number of departments


B. Total employees
C. Sum of department names
D. Error
Answer: A. Total number of departments

57. Which SQL keyword prevents NULLs in a column?


A. CHECK
B. NOT NULL
C. DEFAULT
D. UNIQUE
Answer: B. NOT NULL

58. Which query finds employees who do not belong to any department?
A. SELECT * FROM employees WHERE department IS NULL;
B. SELECT * FROM employees WHERE department_id = '';
C. SELECT * FROM employees WHERE department_id = NULL;
D. SELECT * FROM employees WHERE department_id NOT EXISTS;
Answer: A. SELECT * FROM employees WHERE department IS NULL;

59. Which keyword creates an index on a table?


A. INDEX
B. CREATE INDEX
C. ADD INDEX
D. SET INDEX
Answer: B. CREATE INDEX
60.What is the main advantage of using indexes in SQL?
A. Reduce table size
B. Improve query performance
C. Secure the table
D. Prevent duplication
Answer: B. Improve query performance

61. Which SQL keyword is used to define a virtual table?


A. PROCEDURE
B. TABLE
C. VIEW
D. VIRTUAL
Answer: C. VIEW

62. Which command is used to remove a view in SQL?


A. DELETE VIEW
B. REMOVE VIEW
C. DROP VIEW
D. TRUNCATE VIEW
Answer: C. DROP VIEW

63. Which SQL statement creates a view?


A. CREATE VIRTUAL employees AS SELECT * FROM emp;
B. CREATE TABLE employees AS SELECT * FROM emp;
C. CREATE VIEW employees AS SELECT * FROM emp;
D. VIEW CREATE employees AS SELECT * FROM emp;
Answer: C. CREATE VIEW employees AS SELECT * FROM emp;

64. Which SQL clause is used to rename a table?


A. ALTER NAME
B. RENAME TO
C. CHANGE TABLE
D. RENAME TABLE
Answer: D. RENAME TABLE

65. Which SQL command ensures that all operations in a transaction succeed before
making any changes permanent?
A. SAVE
B. COMMIT
C. EXECUTE
D. FINISH
Answer: B. COMMIT

66. Which command is used to undo a transaction?


A. CANCEL
B. REVERT
C. ROLLBACK
D. DELETE
Answer: C. ROLLBACK

67. Which keyword is used to start a transaction explicitly?


A. BEGIN
B. TRANSACTION
C. START
D. BEGIN TRANSACTION
Answer: D. BEGIN TRANSACTION

68. In which SQL isolation level is a dirty read possible?


A. SERIALIZABLE
B. READ COMMITTED
C. READ UNCOMMITTED
D. REPEATABLE READ
Answer: C. READ UNCOMMITTED

69. Which operation combines results of two SELECTs, removing duplicates?


A. JOIN
B. UNION
C. INTERSECT
D. MERGE
Answer: B. UNION

70. Which operation returns only common rows between two queries?
A. JOIN
B. UNION
C. INTERSECT
D. MINUS
Answer: C. INTERSECT
71. Which operation returns rows from the first query not in the second?
A. INTERSECT
B. EXCEPT / MINUS
C. UNION
D. JOIN
Answer: B. EXCEPT / MINUS

72. What is the highest level of normalization in practical use?


A. 1NF
B. 2NF
C. 3NF
D. BCNF
Answer: D. BCNF

73. Which of the following ensures atomicity in SQL?


A. TRUNCATE
B. SAVEPOINT
C. TRANSACTION
D. COMMIT
Answer: C. TRANSACTION

74. Which keyword saves the current state of a transaction?


A. COMMIT
B. SAVEPOINT
C. ROLLBACK
D. CHECKPOINT
Answer: B. SAVEPOINT

75. Which of the following is NOT a SQL set operator?


A. UNION
B. INTERSECT
C. EXCEPT
D. JOIN
Answer: D. JOIN

76. Which level of normalization removes partial dependency?


A. 1NF
B. 2NF
C. 3NF
D. BCNF
Answer: B. 2NF

77. Which normal form removes transitive dependency?


A. 1NF
B. 2NF
C. 3NF
D. BCNF
Answer: C. 3NF

78. Which SQL function is used to return the current timestamp?


A. SYSDATE
B. NOW()
C. CURRENT_TIMESTAMP
D. All of the above
Answer: D. All of the above

79. Which clause limits the number of rows returned in SQL?


A. LIMIT
B. TOP
C. ROWNUM
D. All of the above (depending on DBMS)
Answer: D. All of the above

80. Which of the following is true about a view?


A. It stores data permanently
B. It is a stored procedure
C. It is a virtual table
D. It has its own indexes
Answer: C. It is a virtual table

You might also like