Font size
WorksheetsSQL Multiple Choice Worksheet
Total questions: 100
Worksheet time: 50mins
SQL stands for:
Simple Query Language
Structured Query Language
Strong Question Logic
Storage Query Language
Which keyword retrieves data from a table?
GET
READ
SELECT
FETCH
Select all columns from employees:
SELECT employees;
SELECT ALL FROM employees;
SELECT * FROM employees;
SHOW employees;
Which keyword removes duplicates?
UNIQUE
DISTINCT
SEPARATE
CLEAR
Which clause filters rows?
ORDER BY
GROUP BY
WHERE
SET
Choose the correct syntax for sorting ascending:
ORDER UP col;
ORDER BY col ASC;
SORT col;
ASCENDING col;
Which operator searches patterns?
LIKE
MATCH
SEARCH
FIND
Which operator selects within a range?
RANGE
LIMIT
BETWEEN
Which operator checks membership in a list?
HAS
LIST
AMONG
IN
Which function counts rows?
SUM()
AVG()
TOTAL()
COUNT()
Which keyword adds new rows?
ADD
INSERT
UPDATE
INCLUDE
Which keyword modifies existing rows?
CHANGE
REWRITE
UPDATE
MODIFY
Which keyword deletes rows?
DELETE
REMOVE
CUT
DROP
Which clause groups rows?
ORDER BY
GROUP BY
HAVING
JOIN
HAVING is used with:
SELECT
DELETE
GROUP BY
INSERT
To get average salary:
AVG(salary)
MEAN(salary)
AVERAGE salary
COUNT(salary)
Which is an aggregate function?
SUBSTR()
COUNT()
REPLACE()
TRIM()
LIMIT is used to:
Restrict number of rows
Rename column
Add constraint
Set default value
What does IS NULL check?
If value is empty string
If value is zero
If value is NULL
If value is missing column
Which returns unique departments?
SELECT ONLY dept FROM emp;
SELECT UNIQUE dept FROM emp;
SELECT DISTINCT dept FROM emp;
SELECT dept UNIQUE;
Default join type:
CROSS
FULL
INNER
LEFT
Join two tables:
SELECT * MERGE a b;
SELECT * FROM a JOIN b ON condition;
SELECT a WITH b;
SELECT * COMBINE a b;
Which join returns all rows from left table?
RIGHT
INNER
LEFT
FULL
Join returning all rows from both tables:
(a)
To get unmatched left rows:
RIGHT JOIN
LEFT JOIN + WHERE right.id IS NULL
INNER JOIN
FULL JOIN
Self join means:
A. A table joins with itself
B. A user joins two tables
C. Joining identical schemas
D. Using CROSS JOIN
CROSS JOIN produces:
Filtered rows
Cartesian product
Full outer join
Unique rows
Which join uses matching column names automatically?
INNER
NATURAL
LEFT
CROSS
UNION does what?
Joins columns
Combines rows without duplicates
Combines rows with duplicates
Merges tables physically
UNION ALL does what?
Removes duplicates
Adds constraints
Keeps duplicates
Sorts results
Which join returns only matched rows?
FULL
INNER
LEFT
RIGHT
Which clause is required for join?
A. ON
B. USE
C. MAP
Non-equi join uses:
=
LIKE
BETWEEN / < / >
AND
Which join can produce the largest number of rows?
INNER
CROSS
LEFT
RIGHT
Which join returns unmatched rows from right table?
LEFT
INNER
RIGHT
FULL
NATURAL JOIN matches columns by:
Length
Position
Name
Data type
Two queries merged into one result set:
EXCEPT
MERGE
UNION
ADD
Which eliminates duplicates?
UNION
UNION ALL
JOIN
MERGE
FULL JOIN missing row output:
Only matched rows
Unmatched + matched rows
Only unmatched
Only left rows
Each join must specify:
Data type
Primary key
Condition
Constraints
Creates a table:
MAKE TABLE
BUILD TABLE
CREATE TABLE
NEW TABLE
Primary key must be:
Unique & Not Null
Unique only
Not null only
Random
Foreign key refers to:
A random column
A view
A primary key in another table
A unique index
Unique constraint allows:
No duplicates
Only NULL
No NULL
Unlimited values
NOT NULL ensures:
Column cannot be zero
Column cannot be blank
Column cannot be NULL
Column must be unique
CHECK constraint tests:
Format
A specific condition
User privilege
Index
DELETE removes:
Only table structure
Rows
Columns
Primary key
TRUNCATE removes:
Table
Indexed columns
All rows quickly
DROP TABLE removes:
Rows only
Columns only
Entire table structure
Indexes only
ALTER TABLE is used to:
Insert rows
Modify table structure
Select rows
Delete records
51. ADD COLUMN syntax:
ALTER TABLE t ADD col datatype;
ADD col datatype TO t;
t ADD col;
MODIFY t ADD col;
Composite key is:
A key from another table
Multiple columns making a primary key
A unique index
A key with default value
ON DELETE CASCADE does:
Prevent delete
Deletes parent only
Deletes child rows automatically
Ignores delete
A schema is:
A. A trigger
B. A database user
C. A collection of tables
D. A stored procedure
Which is DDL?
INSERT
UPDATE
CREATE
DELETE
DML includes:
DROP
CREATE
ALTER
SELECT
UNIQUE allows how many NULLs?
None
One
Many (DB-dependent but usually many)
Unlimited non-NULLs
DEFAULT does what?
Calculates new values
Sets a fallback value
Creates an index
Creates a trigger
Command to rename table (MySQL):
RENAME TO
CHANGE TABLE
RENAME TABLE old TO new
NEW TABLE NAME
Command to delete a column:
DELETE COLUMN col;
ALTER TABLE t DROP COLUMN col;
REMOVE col;
DROP col;
A subquery is:
A comment
A query inside another query
A stored function
A temporary table
Subqueries can be used in:
WHERE
FROM
SELECT
All of the above
Correlated subquery:
Runs independently
Refers to outer query
Uses no tables
Is always faster
EXISTS returns:
The count
True/false
ANY means:
Compare with all values
Compare with at least one value
Compare with none
Compare with two values
ALL means:
Compare with all values
Compare with some values
Compare with one value
Always return true
A derived table is:
A. A temporary table
B. A subquery in FROM
C. A permanent table
D. A view
A view is:
Actual stored data
Virtual table
Index
Trigger
Materialized view:
Always empty
Virtual only
Stores physical data
Cannot be queried
2nd highest salary:
MAX(salary)
MIN(salary)
ORDER BY salary LIMIT 2
Using subquery
Query to find duplicates uses:
WHERE
HAVING COUNT(*) > 1
ORDER BY
DISTINCT
Subquery returning multiple rows is used with:
=
IN
LIKE
When subquery returns >1 row and = is used:
Works fine
Error
Warning only
Returns NULL
DELETE duplicates keeping one:
Impossible
Using correlated query
Using CROSS JOIN
Using HAVING only
A CTE begins with:
BEGIN
WITH
DEFINE
TEMP
Recursive CTE is used for:
Sorting
Tree / hierarchy traversal
Grouping
Indexing
Window functions use:
OVER()
UNDER()
RANGE()
ROWS() only
Rank without gaps:
ROW_NUMBER
RANK
DENSE_RANK
LEAD
Function to look at previous row:
NEXT
LAG
LEAD
BACK
Running total uses:
COUNT()
SUM() OVER()
TOTAL()
ADD()
Index improves:
Storage size
Speed of queries
Table creation
Triggers
Index not useful on:
Unique values
Primary keys
Low-cardinality columns
Foreign keys
Clustered index determines:
Primary key
Physical table order
Logical view order
Temporary sorting
Non-clustered index stores:
Table data itself
Pointer to data
Triggers
Constraints
ACID: A stands for
Addition
Atomicity
Accessibility
Action
Transaction begins with:
RUN
BEGIN
OPEN
START ONLY
COMMIT does what?
Undo changes
Save changes
Lock table
Close database
ROLLBACK does:
Save
Undo
Delete
Deadlock is:
Too many rows
Two transactions waiting on each other
Data corruption
Missing indexes
Foreign key ensures:
Performance
Referential integrity
Faster SELECT
Automatic indexing
A trigger runs:
Automatically on events
Only manually
On server restart
Once per day
Stored procedure is:
Query history
Saved SQL code
Database schema
Constraint
COALESCE returns:
Lowest value
First non-NULL value
Last row
Largest value
NULL means:
Zero
Empty string
Unknown / missing
False
Which handles string matching?
LIKE
MATCH() only
IN
AS
What does ORDER BY 1 mean?
Order by first row
Order by first column
Order randomly
Order by ID only
Which removes whitespace?
CUT
TRIM
DELETE
CLEAN
Which extracts substring?
SUBSTR()
CUT()
TAKE()
MID only
Which returns current date?
NOW()
DATE()
TODAY()
TIME()
Replace NULL salary with 0:
IFNULL(salary)
COALESCE(salary, 0)
NULL(salary, 0)
REPLACE(salary)
