100 SQL MCQ (Multiple Choice Questions) with Answers

1) Which SQL statement is used to extract data from a database?
  1. EXTRACT
  2. GET
  3. OPEN
  4. SELECT
Show Answer
Answer: d


2) Which SQL clause is used to filter records?

  1. WHERE
  2. FILTER
  3. GROUP BY
  4. SEARCH
Show Answer
Answer: a


3) Which keyword is used to sort the result set in ascending order by default?

  1. SORT BY
  2. ORDER BY
  3. GROUP BY
  4. ALIGN BY
Show Answer
Answer: b


4) How do you select all columns from a table named `Users`?

  1. SELECT Users;
  2. SELECT * FROM Users;
  3. SELECT all FROM Users;
  4. GET * FROM Users;
Show Answer
Answer: b


5) Which SQL operator is used to search for a specified pattern in a column?

  1. LIKE
  2. IN
  3. BETWEEN
  4. MATCH
Show Answer
Answer: a


6) Which function returns the total number of rows in a table?

  1. SUM()
  2. TOTAL()
  3. COUNT()
  4. NUMBER()
Show Answer
Answer: c


7) Which command is used to remove all records from a table without removing the table structure?

  1. DROP
  2. DELETE
  3. REMOVE
  4. TRUNCATE
Show Answer
Answer: d


8) Which constraint ensures that all values in a column are unique?

  1. FOREIGN KEY
  2. CHECK
  3. UNIQUE
  4. DEFAULT
Show Answer
Answer: c


9) Which SQL clause is used to aggregate data by one or more columns?

  1. ORDER BY
  2. GROUP BY
  3. HAVING
  4. ALIGN BY
Show Answer
Answer: b


10) Which clause is used to filter groups created by `GROUP BY`?

  1. WHERE
  2. HAVING
  3. FILTER
  4. LIMIT
Show Answer
Answer: b


11) What type of JOIN returns records that have matching values in both tables?

  1. LEFT JOIN
  2. RIGHT JOIN
  3. INNER JOIN
  4. FULL OUTER JOIN
Show Answer
Answer: c


12) Which statement is used to insert new data into a database?

  1. ADD RECORD
  2. INSERT INTO
  3. UPDATE
  4. MAKE NEW
Show Answer
Answer: b


13) Which command completely deletes a table and its structure from the database?

  1. TRUNCATE TABLE
  2. DELETE TABLE
  3. REMOVE TABLE
  4. DROP TABLE
Show Answer
Answer: d


14) Which wildcard character represents zero or more characters in SQL `LIKE` queries?

  1. %
  2. _
  3. *
  4. #
Show Answer
Answer: a


15) Which wildcard character represents a single character in standard SQL `LIKE` queries?

  1. %
  2. _
  3. ?
  4. #
Show Answer
Answer: b


16) Which SQL keyword is used to modify existing records in a table?

  1. MODIFY
  2. CHANGE
  3. UPDATE
  4. SAVE
Show Answer
Answer: c


17) What does `NULL` represent in SQL?

  1. Zero
  2. An empty text string
  3. Missing or unknown value
  4. False
Show Answer
Answer: c


18) Which statement is used to create a new database?

  1. CREATE DB
  2. NEW DATABASE
  3. CREATE DATABASE
  4. MAKE DATABASE
Show Answer
Answer: c


19) Which constraint uniquely identifies each record in a database table?

  1. FOREIGN KEY
  2. PRIMARY KEY
  3. UNIQUE KEY
  4. CHECK KEY
Show Answer
Answer: b


20) Which command saves pending transaction changes permanently to the database?

  1. ROLLBACK
  2. SAVEPOINT
  3. COMMIT
  4. STORE
Show Answer
Answer: c


21) Which function returns the largest value in a selected column?

  1. MAX()
  2. HIGH()
  3. TOP()
  4. GREATEST()
Show Answer
Answer: a


22) Which function returns the average value of a numeric column?

  1. AVERAGE()
  2. AVG()
  3. MEAN()
  4. SUM()
Show Answer
Answer: b


23) Which clause is used to limit the number of rows returned in MySQL or PostgreSQL?

  1. ROWNUM
  2. TOP
  3. LIMIT
  4. FETCH
Show Answer
Answer: c


24) What type of key links two tables together in a relational database?

  1. PRIMARY KEY
  2. FOREIGN KEY
  3. COMPOSITE KEY
  4. CANDIDATE KEY
Show Answer
Answer: b


25) Which SQL operator allows you to specify multiple values in a `WHERE` clause?

  1. IN
  2. BETWEEN
  3. LIKE
  4. ANY
Show Answer
Answer: a


26) Which SQL operator is used to select values within an inclusive range?

  1. WITHIN
  2. RANGE
  3. BETWEEN
  4. IN
Show Answer
Answer: c


27) Which keyword is used to return only distinct (unique) values?

  1. UNIQUE
  2. DISTINCT
  3. DIFFERENT
  4. INDIVIDUAL
Show Answer
Answer: b


28) What type of JOIN returns all rows from the left table, and matching rows from the right table?

  1. INNER JOIN
  2. RIGHT JOIN
  3. LEFT JOIN
  4. FULL JOIN
Show Answer
Answer: c


29) What is the default sort order of the `ORDER BY` clause?

  1. ASC
  2. DESC
  3. NONE
  4. RANDOM
Show Answer
Answer: a


30) Which SQL language sub-category includes `SELECT`, `INSERT`, `UPDATE`, and `DELETE`?

  1. DDL
  2. DML
  3. DCL
  4. TCL
Show Answer
Answer: b


31) Which SQL sub-category includes `CREATE`, `ALTER`, and `DROP`?

  1. DDL
  2. DML
  3. DCL
  4. TCL
Show Answer
Answer: a


32) Which SQL command undoes uncommitted transactions?

  1. COMMIT
  2. REVERT
  3. ROLLBACK
  4. UNDO
Show Answer
Answer: c


33) Which SQL operator combines the result sets of two queries and removes duplicates?

  1. UNION ALL
  2. UNION
  3. INTERSECT
  4. JOIN
Show Answer
Answer: b


34) Which operator combines the result sets of two queries including all duplicates?

  1. UNION
  2. UNION ALL
  3. COMBINE ALL
  4. MERGE
Show Answer
Answer: b


35) Which constraint limits the value range that can be placed in a column?

  1. CHECK
  2. DEFAULT
  3. RANGE
  4. BOUND
Show Answer
Answer: a


36) Which keyword is used to add a new column to an existing table?

  1. UPDATE TABLE table_name ADD
  2. ALTER TABLE table_name ADD
  3. MODIFY TABLE table_name INSERT
  4. CHANGE TABLE table_name ADD
Show Answer
Answer: b


37) How do you rename a column in an existing table?

  1. ALTER TABLE table_name RENAME COLUMN old_name TO new_name;
  2. UPDATE TABLE table_name RENAME old_name TO new_name;
  3. MODIFY COLUMN old_name TO new_name;
  4. CHANGE TABLE old_name NEW new_name;
Show Answer
Answer: a


38) What type of JOIN returns all records when there is a match in either left or right table?

  1. INNER JOIN
  2. CROSS JOIN
  3. FULL OUTER JOIN
  4. SELF JOIN
Show Answer
Answer: c


39) A Cartesian product is produced by which type of JOIN?

  1. CROSS JOIN
  2. INNER JOIN
  3. LEFT JOIN
  4. NATURAL JOIN
Show Answer
Answer: a


40) Which command grants privileges to users in a database?

  1. ALLOW
  2. GRANT
  3. PERMIT
  4. GIVE
Show Answer
Answer: b


41) Which command revokes privileges previously granted to users?

  1. DENY
  2. REVOKE
  3. TAKE
  4. REMOVE
Show Answer
Answer: b


42) Which aggregate function returns the total sum of a numeric column?

  1. TOTAL()
  2. COUNT()
  3. SUM()
  4. ADD()
Show Answer
Answer: c


43) Which function returns the smallest value of a selected column?

  1. LEAST()
  2. MIN()
  3. LOW()
  4. BOTTOM()
Show Answer
Answer: b


44) What does the `IS NULL` operator check for?

  1. Empty strings
  2. Zero values
  3. Missing values
  4. False values
Show Answer
Answer: c


45) Which clause is evaluated FIRST in standard SQL query execution order?

  1. SELECT
  2. WHERE
  3. FROM
  4. GROUP BY
Show Answer
Answer: c


46) Which clause is evaluated LAST in standard SQL query execution order?

  1. SELECT
  2. ORDER BY
  3. HAVING
  4. LIMIT
Show Answer
Answer: d


47) What statement creates a virtual table based on the result-set of an SQL statement?

  1. CREATE TABLE
  2. CREATE VIEW
  3. CREATE VIRTUAL
  4. CREATE INDEX
Show Answer
Answer: b


48) What database object is used to speed up data retrieval performance?

  1. TRIGGER
  2. VIEW
  3. INDEX
  4. PROCEDURE
Show Answer
Answer: c


49) How do you delete all data from a table named `Logs` using DML?

  1. DROP TABLE Logs;
  2. TRUNCATE Logs;
  3. DELETE FROM Logs;
  4. REMOVE * FROM Logs;
Show Answer
Answer: c


50) Which operator tests whether a subquery returns any rows?

  1. IN
  2. EXISTS
  3. ANY
  4. ALL
Show Answer
Answer: b


51) Which statement drops an existing view?

  1. DELETE VIEW view_name;
  2. DROP VIEW view_name;
  3. TRUNCATE VIEW view_name;
  4. REMOVE VIEW view_name;
Show Answer
Answer: b


52) What type of JOIN joins a table to itself?

  1. SELF JOIN
  2. INNER JOIN
  3. AUTO JOIN
  4. CROSS JOIN
Show Answer
Answer: a


53) What constraint automatically assigns a value to a column when no value is specified?

  1. DEFAULT
  2. AUTO
  3. PRESET
  4. CHECK
Show Answer
Answer: a


54) Which keyword is used to remove a primary key constraint from a table?

  1. ALTER TABLE table_name DROP PRIMARY KEY;
  2. DROP PRIMARY KEY FROM table_name;
  3. DELETE PRIMARY KEY;
  4. REMOVE PRIMARY KEY FROM table_name;
Show Answer
Answer: a


55) In SQL, what is a subquery?

  1. A query embedded inside another query
  2. A stored procedure
  3. A view definition
  4. A database index
Show Answer
Answer: a


56) Which operator returns TRUE if ALL subquery values meet the condition?

  1. ANY
  2. ALL
  3. SOME
  4. EXISTS
Show Answer
Answer: b


57) Which function converts a string to uppercase in standard SQL?

  1. UPPER()
  2. MAXSTRING()
  3. CAPITALIZE()
  4. TOUPPER()
Show Answer
Answer: a


58) Which scalar function removes leading and trailing spaces from a string?

  1. CUT()
  2. TRIM()
  3. STRIP()
  4. CLEAN()
Show Answer
Answer: b


59) Which function returns the current system date and time in SQL Server?

  1. NOW()
  2. GETDATE()
  3. CURRENT_TIMESTAMP()
  4. SYSDATE
Show Answer
Answer: b


60) Which statement is used to execute a stored procedure in SQL Server?

  1. RUN
  2. EXEC
  3. CALL
  4. START
Show Answer
Answer: b


61) What automatically executes in response to certain events on a table?

  1. Index
  2. View
  3. Trigger
  4. Sequence
Show Answer
Answer: c


62) Which normalization level eliminates repeating groups?

  1. 1NF
  2. 2NF
  3. 3NF
  4. BCNF
Show Answer
Answer: a


63) Which normalization form requires removing transitive dependencies?

  1. 1NF
  2. 2NF
  3. 3NF
  4. BCNF
Show Answer
Answer: c


64) A primary key composed of two or more columns is known as a:

  1. Foreign key
  2. Composite key
  3. Super key
  4. Candidate key
Show Answer
Answer: b


65) Which command permanently deletes a database?

  1. DROP DATABASE db_name;
  2. DELETE DATABASE db_name;
  3. TRUNCATE DATABASE db_name;
  4. REMOVE DATABASE db_name;
Show Answer
Answer: a


66) Which set operator returns only rows common to both query results?

  1. UNION
  2. EXCEPT
  3. INTERSECT
  4. MINUS
Show Answer
Answer: c


67) Which SQL keyword replaces `INTERSECT` for set difference in Oracle?

  1. EXCEPT
  2. MINUS
  3. DIFFERENCE
  4. SUBTRACT
Show Answer
Answer: b


68) Which function replaces NULL values with a specified replacement value?

  1. COALESCE()
  2. IFNULL()
  3. NVL()
  4. All of the above (depending on RDBMS)
Show Answer
Answer: d


69) What will `COALESCE(NULL, NULL, ‘SQL’, ‘Python’)` return?

  1. NULL
  2. SQL
  3. Python
  4. Error
Show Answer
Answer: b


70) Which constraint prevents `NULL` values from being inserted into a column?

  1. UNIQUE
  2. CHECK
  3. NOT NULL
  4. DEFAULT
Show Answer
Answer: c


71) What does the `ROLLBACK` command do?

  1. Saves changes to database
  2. Reverts transactions since last commit
  3. Deletes table
  4. Restores backups
Show Answer
Answer: b


72) Which clause assigns an alias to a column or table?

  1. LIKE
  2. AS
  3. IS
  4. WITH
Show Answer
Answer: b


73) What is the result of `10 / NULL` in SQL?

  1. 0
  2. 10
  3. NULL
  4. Syntax Error
Show Answer
Answer: c


74) Which conditional expression acts like an IF-THEN-ELSE statement in SQL?

  1. CASE
  2. IF
  3. CHOOSE
  4. DECODE
Show Answer
Answer: a


75) What command removes an index from a database?

  1. DELETE INDEX
  2. DROP INDEX
  3. REMOVE INDEX
  4. ALTER INDEX DROP
Show Answer
Answer: b


76) Which function is used to calculate string length in SQL Server?

  1. LENGTH()
  2. LEN()
  3. SIZE()
  4. CHAR_LEN()
Show Answer
Answer: b


77) What type of lock allows multiple transactions to read a resource simultaneously?

  1. Exclusive Lock
  2. Shared Lock
  3. Update Lock
  4. Intent Lock
Show Answer
Answer: b


78) Which window function assigns a unique sequential integer to rows starting at 1?

  1. RANK()
  2. DENSE_RANK()
  3. ROW_NUMBER()
  4. NTILE()
Show Answer
Answer: c


79) What is the difference between `RANK()` and `DENSE_RANK()` upon encountering ties?

  1. `RANK()` skips rank numbers; `DENSE_RANK()` does not
  2. `DENSE_RANK()` skips rank numbers; `RANK()` does not
  3. Both skip numbers
  4. Neither skips numbers
Show Answer
Answer: a


80) Which clause is required when using window functions like `ROW_NUMBER()`?

  1. GROUP BY
  2. OVER()
  3. HAVING
  4. INTO
Show Answer
Answer: b


81) Which window function partitions the rows into a specified number of equal groups?

  1. NTILE()
  2. CUME_DIST()
  3. PERCENT_RANK()
  4. LAG()
Show Answer
Answer: a


82) Which function accesses data from a previous row in the same result set without using a self-join?

  1. LEAD()
  2. LAG()
  3. FIRST_VALUE()
  4. PRIOR()
Show Answer
Answer: b


83) Which function accesses data from a subsequent row in the same result set?

  1. LAG()
  2. LEAD()
  3. NEXT_VALUE()
  4. AFTER()
Show Answer
Answer: b


84) What property in ACID guarantees that all operations within a transaction complete successfully or fail completely?

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability
Show Answer
Answer: a


85) What property in ACID ensures committed data is saved even during a system crash?

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability
Show Answer
Answer: d


86) A query reading uncommitted data from another concurrent transaction experiences a:

  1. Non-repeatable Read
  2. Phantom Read
  3. Dirty Read
  4. Lost Update
Show Answer
Answer: c


87) Which isolation level completely prevents Dirty Reads, Non-repeatable Reads, and Phantom Reads?

  1. Read Uncommitted
  2. Read Committed
  3. Repeatable Read
  4. Serializable
Show Answer
Answer: d


88) What does CTE stand for in SQL?

  1. Common Table Expression
  2. Combined Table Element
  3. Control Table Execution
  4. Centralized Transaction Engine
Show Answer
Answer: a


89) Which clause is used to define a Common Table Expression (CTE)?

  1. WITH
  2. CTE
  3. DEFINE
  4. LET
Show Answer
Answer: a


90) Which join type returns all rows from both tables, filling missing matches with NULLs?

  1. INNER JOIN
  2. LEFT JOIN
  3. RIGHT JOIN
  4. FULL OUTER JOIN
Show Answer
Answer: d


91) What type of command is `SAVEPOINT`?

  1. DDL
  2. DML
  3. TCL
  4. DCL
Show Answer
Answer: c


92) How do you delete duplicate rows while retaining one copy in SQL?

  1. TRUNCATE DUPLICATES
  2. Using a CTE with `ROW_NUMBER()`
  3. DELETE DISTINCT
  4. DROP DUPLICATES
Show Answer
Answer: b


93) What is the default index type created on a Primary Key in SQL Server?

  1. Non-clustered index
  2. Clustered index
  3. Unique non-clustered index
  4. Filtered index
Show Answer
Answer: b


94) How many clustered indexes can exist on a single table?

  1. 1
  2. 2
  3. 16
  4. Unlimited
Show Answer
Answer: a


95) What is the key characteristic of a clustered index?

  1. It physically sorts and stores data rows in the table
  2. It creates a secondary pointers list
  3. It applies only to string columns
  4. It automatically updates views
Show Answer
Answer: a


96) Which keyword prevents a transaction from locking an entire table when reading data in SELECT statements?

  1. NOLOCK
  2. NOREAD
  3. UNLOCK
  4. FAST
Show Answer
Answer: a


97) What is an inline table-valued function?

  1. A function returning a single scalar value
  2. A function returning a table data type based on a single `SELECT` statement
  3. A stored procedure returning output parameters
  4. A view that executes on a schedule
Show Answer
Answer: b


98) What happens to a foreign key constraint by default if you attempt to delete a referenced row in a parent table?

  1. Parent row is deleted automatically
  2. Child rows are set to NULL
  3. Action is blocked (raises foreign key constraint error)
  4. Parent and child tables are dropped
Show Answer
Answer: c


99) Which option on a foreign key constraint causes matching child rows to be deleted automatically when a parent row is deleted?

  1. ON DELETE SET NULL
  2. ON DELETE CASCADE
  3. ON DELETE RESTRICT
  4. ON DELETE NO ACTION
Show Answer
Answer: b


100) What SQL feature allows writing recursive queries for hierarchical data structures?

  1. Recursive CTE
  2. Dynamic SQL
  3. Pivot Operator
  4. Cursor Loops
Show Answer
Answer: a

 

100 C++ MCQ (Multiple Choice Questions) with Answers
100 MySQL MCQ (Multiple Choice Questions) with Answers
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment