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
Explanation
SELECT is the standard SQL statement used to query and retrieve data from database tables.


2) Which SQL clause is used to filter records?

  1. WHERE
  2. FILTER
  3. GROUP BY
  4. SEARCH
Show Answer
Answer: a
Explanation
WHERE is used to filter individual rows before grouping or aggregation.


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
Explanation
ORDER BY sorts query results. If ASC or DESC is not specified, ascending order is used by default.


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
Explanation
The asterisk (*) is a wildcard meaning all columns, so SELECT * FROM Users retrieves every column from the Users table.


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
Explanation
LIKE is used with wildcards such as % and _ to match string patterns.


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

  1. SUM()
  2. TOTAL()
  3. COUNT()
  4. NUMBER()
Show Answer
Answer: c
Explanation
COUNT() counts rows or non-null values. COUNT(*) counts all rows in the result set.


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
Explanation
TRUNCATE TABLE quickly removes all rows while keeping the table structure intact. DROP removes the table itself.


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
Explanation
UNIQUE prevents duplicate values in the specified column, although it may allow NULL depending on the database.


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
Explanation
GROUP BY groups rows with the same values in specified columns so aggregate functions can be applied.


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

  1. WHERE
  2. HAVING
  3. FILTER
  4. LIMIT
Show Answer
Answer: b
Explanation
HAVING filters grouped results, while WHERE filters individual rows before grouping.


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
Explanation
INNER JOIN returns only rows where matching values exist in both joined tables.


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
Explanation
INSERT INTO is used to add new rows to a table.


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
Explanation
DROP TABLE removes both the table data and the table definition/structure.


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

  1. %
  2. _
  3. *
  4. #
Show Answer
Answer: a
Explanation
In SQL LIKE patterns, % matches any sequence of zero or more characters.


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

  1. %
  2. _
  3. ?
  4. #
Show Answer
Answer: b
Explanation
The underscore (_) wildcard matches exactly one character in a LIKE pattern.


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
Explanation
UPDATE changes existing row values in a table, usually with a WHERE clause.


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
Explanation
NULL represents a missing, unknown, or not applicable value. It is not equal to zero or an empty string.


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
Explanation
CREATE DATABASE database_name; is the standard SQL statement for creating a new database.


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
Explanation
A PRIMARY KEY uniquely identifies each row and cannot contain NULL values.


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

  1. ROLLBACK
  2. SAVEPOINT
  3. COMMIT
  4. STORE
Show Answer
Answer: c
Explanation
COMMIT permanently saves all changes made during the current transaction.


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

  1. MAX()
  2. HIGH()
  3. TOP()
  4. GREATEST()
Show Answer
Answer: a
Explanation
MAX() returns the largest value in a column or expression.


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

  1. AVERAGE()
  2. AVG()
  3. MEAN()
  4. SUM()
Show Answer
Answer: b
Explanation
AVG() calculates the arithmetic mean of a numeric column.


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
Explanation
MySQL and PostgreSQL use LIMIT to restrict the number of returned rows.


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
Explanation
A FOREIGN KEY references the primary key of another table and creates a relationship between the tables.


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
Explanation
IN checks whether a value matches any value in a specified list.


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
Explanation
BETWEEN checks whether a value lies within a range, and the boundary values are included.


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

  1. UNIQUE
  2. DISTINCT
  3. DIFFERENT
  4. INDIVIDUAL
Show Answer
Answer: b
Explanation
SELECT DISTINCT removes duplicate rows from the result set.


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
Explanation
LEFT JOIN returns all rows from the left table and matching rows from the right; unmatched right-side columns become NULL.


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

  1. ASC
  2. DESC
  3. NONE
  4. RANDOM
Show Answer
Answer: a
Explanation
ORDER BY defaults to ascending order (ASC) when no sort direction is specified.


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

  1. DDL
  2. DML
  3. DCL
  4. TCL
Show Answer
Answer: b
Explanation
DML (Data Manipulation Language) includes statements that query or modify data, such as SELECT, INSERT, UPDATE, and DELETE.


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

  1. DDL
  2. DML
  3. DCL
  4. TCL
Show Answer
Answer: a
Explanation
DDL (Data Definition Language) defines or changes database structures, including CREATE, ALTER, and DROP.


32) Which SQL command undoes uncommitted transactions?

  1. COMMIT
  2. REVERT
  3. ROLLBACK
  4. UNDO
Show Answer
Answer: c
Explanation
ROLLBACK reverses changes made in the current transaction that have not yet been committed.


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
Explanation
UNION combines two result sets and removes duplicate rows.


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
Explanation
UNION ALL combines result sets and keeps all duplicate rows.


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
Explanation
CHECK enforces a Boolean condition on column values, such as Age >= 18.


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
Explanation
ALTER TABLE table_name ADD column_name data_type; adds a new column to an existing table.


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
Explanation
The standard syntax for renaming a column is ALTER TABLE … RENAME COLUMN … TO …; exact syntax may vary slightly by database.


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
Explanation
FULL OUTER JOIN returns all rows from both tables, matching where possible and using NULLs where there is no match.


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
Explanation
CROSS JOIN returns the Cartesian product: every row from the first table paired with every row from the second table.


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

  1. ALLOW
  2. GRANT
  3. PERMIT
  4. GIVE
Show Answer
Answer: b
Explanation
GRANT gives specific privileges, such as SELECT or INSERT, to database users or roles.


41) Which command revokes privileges previously granted to users?

  1. DENY
  2. REVOKE
  3. TAKE
  4. REMOVE
Show Answer
Answer: b
Explanation
REVOKE removes previously granted privileges from a user or role.


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

  1. TOTAL()
  2. COUNT()
  3. SUM()
  4. ADD()
Show Answer
Answer: c
Explanation
SUM() adds all non-null numeric values in a column or expression.


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

  1. LEAST()
  2. MIN()
  3. LOW()
  4. BOTTOM()
Show Answer
Answer: b
Explanation
MIN() returns the smallest value in a column or expression.


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
Explanation
IS NULL checks whether a value is NULL, meaning missing or unknown.


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
Explanation
Logical query processing starts with FROM, which identifies the source tables and joins.


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
Explanation
LIMIT is applied after sorting and filtering, so it is last in the logical execution order.


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
Explanation
CREATE VIEW creates a stored query that behaves like a virtual table.


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

  1. TRIGGER
  2. VIEW
  3. INDEX
  4. PROCEDURE
Show Answer
Answer: c
Explanation
An INDEX improves the speed of data retrieval operations on a table.


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
Explanation
DELETE FROM Logs; is a DML statement that removes all rows while keeping the table structure. TRUNCATE is usually DDL.


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

  1. IN
  2. EXISTS
  3. ANY
  4. ALL
Show Answer
Answer: b
Explanation
EXISTS returns TRUE if the subquery returns at least one row.


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
Explanation
DROP VIEW removes an existing view from the database.


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
Explanation
A SELF JOIN joins a table to itself, usually by using table aliases.


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
Explanation
DEFAULT provides a value automatically when no value is supplied for a column.


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
Explanation
ALTER TABLE … DROP PRIMARY KEY; removes the primary key constraint. Exact syntax may vary by database.


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
Explanation
A subquery is a query nested inside another SQL statement.


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

  1. ANY
  2. ALL
  3. SOME
  4. EXISTS
Show Answer
Answer: b
Explanation
ALL requires the comparison to be true for every value returned by the subquery.


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

  1. UPPER()
  2. MAXSTRING()
  3. CAPITALIZE()
  4. TOUPPER()
Show Answer
Answer: a
Explanation
UPPER() converts all characters in a string to uppercase.


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

  1. CUT()
  2. TRIM()
  3. STRIP()
  4. CLEAN()
Show Answer
Answer: b
Explanation
TRIM() removes leading and trailing spaces from a string.


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
Explanation
In SQL Server, GETDATE() returns the current system date and time.


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
Explanation
EXEC or EXECUTE is used in SQL Server to run a stored procedure.


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

  1. Index
  2. View
  3. Trigger
  4. Sequence
Show Answer
Answer: c
Explanation
A TRIGGER automatically runs when a specified event such as INSERT, UPDATE, or DELETE occurs.


62) Which normalization level eliminates repeating groups?

  1. 1NF
  2. 2NF
  3. 3NF
  4. BCNF
Show Answer
Answer: a
Explanation
First Normal Form (1NF) eliminates repeating groups and ensures atomic column values.


63) Which normalization form requires removing transitive dependencies?

  1. 1NF
  2. 2NF
  3. 3NF
  4. BCNF
Show Answer
Answer: c
Explanation
Third Normal Form (3NF) removes transitive dependencies between non-key attributes.


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
Explanation
A composite key is a primary key made up of two or more columns.


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
Explanation
DROP DATABASE permanently removes the database and its objects.


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

  1. UNION
  2. EXCEPT
  3. INTERSECT
  4. MINUS
Show Answer
Answer: c
Explanation
INTERSECT returns only the rows that appear in both result sets.


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

  1. EXCEPT
  2. MINUS
  3. DIFFERENCE
  4. SUBTRACT
Show Answer
Answer: b
Oracle uses MINUS for set difference instead of EXCEPT.


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
Explanation
COALESCE(), IFNULL(), and NVL() all replace NULLs, but availability depends on the database system.


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

  1. NULL
  2. SQL
  3. Python
  4. Error
Show Answer
Answer: b
Explanation
COALESCE returns the first non-NULL argument, which is ‘SQL’.


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
Explanation
NOT NULL requires that every row has a non-NULL value in the column.


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
Explanation
ROLLBACK undoes uncommitted changes made since the last COMMIT or SAVEPOINT.


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

  1. LIKE
  2. AS
  3. IS
  4. WITH
Show Answer
Answer: b
Explanation
AS assigns an alias to a column or table, for example SELECT Name AS CustomerName.


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

  1. 0
  2. 10
  3. NULL
  4. Syntax Error
Show Answer
Answer: c
Explanation
Any arithmetic operation involving NULL generally returns NULL.


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
Explanation
CASE provides conditional logic similar to IF-THEN-ELSE within SQL statements.


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
Explanation
DROP INDEX removes an existing index from the database.


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
Explanation
SQL Server uses LEN() to return the length of a string, excluding trailing spaces.


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
Explanation
A shared lock allows concurrent reads but prevents writes while the lock is held.


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
Explanation
ROW_NUMBER() assigns a unique sequential number to each row within a partition.


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
Explanation
RANK() leaves gaps after ties, while DENSE_RANK() assigns consecutive ranks without gaps.


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
Explanation
Window functions require the OVER() clause to define the partition and ordering.


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
Explanation
NTILE(n) divides the result set into n roughly equal groups.


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
Explanation
LAG() returns a value from a previous row in the same result set.


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
Explanation
LEAD() returns a value from a following row in the same result set.


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
Explanation
Atomicity means a transaction is treated as a single all-or-nothing unit.


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
Explanation
Durability guarantees that committed changes persist even after a crash or power failure.


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
Explanation
A dirty read occurs when one transaction reads data changed by another transaction that has not yet committed.


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
Explanation
Serializable is the strictest isolation level and prevents dirty reads, non-repeatable reads, and phantom reads.


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
Explanation
CTE stands for Common Table Expression, a temporary named result set defined with WITH.


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

  1. WITH
  2. CTE
  3. DEFINE
  4. LET
Show Answer
Answer: a
Explanation
A CTE is defined using the WITH clause before the main query.


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
Explanation
FULL OUTER JOIN returns all rows from both tables and uses NULLs for missing matches.


91) What type of command is `SAVEPOINT`?

  1. DDL
  2. DML
  3. TCL
  4. DCL
Show Answer
Answer: c
Explanation
SAVEPOINT is a Transaction Control Language (TCL) command used to mark a point within a transaction.


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
Explanation
A common technique is to use a CTE with ROW_NUMBER() and delete rows where the row number is greater than 1.


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
Explanation
In SQL Server, a primary key creates a clustered index by default unless specified otherwise.


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

  1. 1
  2. 2
  3. 16
  4. Unlimited
Show Answer
Answer: a
Explanation
A table can have only one clustered index because it defines the physical order of the rows.


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
Explanation
A clustered index determines the physical storage order of rows in the table.


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
Explanation
NOLOCK allows a read without taking shared locks, though it can permit dirty reads.


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
Explanation
An inline table-valued function returns a table based on a single SELECT statement.


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
Explanation
By default, deleting a parent row referenced by a foreign key is blocked to preserve referential integrity.


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
Explanation
ON DELETE CASCADE automatically deletes child rows that reference a deleted parent row.


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
Explanation
A Recursive CTE references itself and is commonly used for hierarchical or tree-structured data.

 

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