SQL MCQs
20 practice MCQs on this page Page 3 of 4
Tap an option to check your answer — the correct answer and full explanation appear after you choose.
Computer ScienceSQL BPSCID: BPP-2747
Which SQL command is used to modify existing data?
- ADROP
- BSELECT
- CUPDATE ✓ Correct answer
- DINSERT
✓ Correct answer: UPDATE
Full explanation
The UPDATE command is used to modify existing data in a table.
Computer ScienceSQL BPSCID: BPP-2748
Which SQL command removes data from a table?
- AREMOVE
- BDELETE ✓ Correct answer
- CTRUNCATE
- DDROP
✓ Correct answer: DELETE
Full explanation
The DELETE command removes data from a table.
Computer ScienceSQL FPSCID: FPP-11388
Which SQL statement is used to create a database?
- AADD DATABASE
- BCREATE DATABASE ✓ Correct answer
- CMAKE DATABASE
- DNEW DATABASE
✓ Correct answer: CREATE DATABASE
Full explanation
The CREATE DATABASE statement is used to create a database in SQL.
Computer ScienceSQL FPSCID: FPP-11391
Which of the following is a DDL command?
- AUPDATE
- BSELECT
- CINSERT
- DCREATE ✓ Correct answer
✓ Correct answer: CREATE
Full explanation
CREATE is a DDL (Data Definition Language) command.
Computer ScienceSQL FPSCID: FPP-11392
Which of the following is a DML command?
- ACREATE
- BDROP
- CINSERT ✓ Correct answer
- DALTER
✓ Correct answer: INSERT
Full explanation
INSERT is a DML (Data Manipulation Language) command.
Computer ScienceSQL PPSCID: LTP-7771
Which SQL statement is used to change the values in existing rows?
- ASELECT
- BCREATE
- CGRANT
- DUPDATE ✓ Correct answer
✓ Correct answer: UPDATE
Full explanation
The UPDATE statement is used in SQL to change the values in existing rows of a table.
Computer ScienceSQL PPSCID: LTP-7772
Which SQL statement is used to remove rows from a table?
- ADELETE FROM ✓ Correct answer
- BDROP TABLE
- CTRUNCATE TABLE
- DREMOVE FROM
✓ Correct answer: DELETE FROM
Full explanation
The DELETE FROM statement is used in SQL to remove rows from a table, while the table itself remains.
Computer ScienceSQL PPSCID: LTP-7773
What is the difference between DROP TABLE and TRUNCATE TABLE?
- ATRUNCATE removes the whole table; DROP removes only its rows
- BDROP removes the whole table; TRUNCATE removes only its rows ✓ Correct answer
- CBoth delete the database
- DBoth only delete one row
✓ Correct answer: DROP removes the whole table; TRUNCATE removes only its rows
Full explanation
DROP removes the whole table; TRUNCATE removes only its rows — DROP deletes the structure too, while TRUNCATE keeps the empty table.
Computer ScienceSQL PPSCID: LTP-7774
Which SQL statement is used to change the structure of an existing table?
- AUPDATE TABLE
- BMODIFY DATA
- CALTER TABLE ✓ Correct answer
- DCHANGE ROW
✓ Correct answer: ALTER TABLE
Full explanation
The ALTER TABLE statement is used in SQL to change the structure of an existing table, such as adding a column.
Computer ScienceSQL PPSCID: LTP-7775
Which SQL clause is used to filter rows before they are returned?
- AHAVING
- BORDER BY
- CGROUP BY
- DWHERE ✓ Correct answer
✓ Correct answer: WHERE
Full explanation
The WHERE clause filters rows before they are returned, keeping only the rows that meet the condition.
Computer ScienceSQL PPSCID: LTP-7776
In SQL, which operator is used with WHERE to match a pattern in text?
- ALIKE ✓ Correct answer
- BBETWEEN
- CIN
- DIS
✓ Correct answer: LIKE
Full explanation
The LIKE operator is used with WHERE to match a pattern in text, using % for any characters and _ for one character.
Computer ScienceSQL PPSCID: LTP-7777
In SQL, the BETWEEN operator is used to select values:
- AOutside all ranges
- BWithin a given range ✓ Correct answer
- COnly equal to zero
- DOnly in text columns
✓ Correct answer: Within a given range
Full explanation
The BETWEEN operator selects values within a given range, including both ends of the range.
Computer ScienceSQL PPSCID: LTP-7778
In SQL, the IN operator is used to:
- ADelete a list
- BSort a list
- CMatch any value in a list ✓ Correct answer
- DCreate a list
✓ Correct answer: Match any value in a list
Full explanation
The IN operator is used to match any value in a list, so WHERE city IN ('Lahore', 'Karachi') finds rows with either city.
Computer ScienceSQL PPSCID: LTP-7779
In SQL, which condition correctly tests whether a column has no value?
- A= NULL
- B== NULL
- CIS EMPTY
- DIS NULL ✓ Correct answer
✓ Correct answer: IS NULL
Full explanation
In SQL the IS NULL condition tests whether a column has no value, because NULL cannot be compared with =.
Computer ScienceSQL PPSCID: LTP-7780
In SQL, ORDER BY with DESC sorts the results in which order?
- ADescending order ✓ Correct answer
- BAscending order
- CRandom order
- DNo order
✓ Correct answer: Descending order
Full explanation
ORDER BY with DESC sorts the results in descending order, from the largest value to the smallest.
Computer ScienceSQL PPSCID: LTP-7781
Which SQL function returns the average value of a numeric column?
- ASUM
- BAVG ✓ Correct answer
- CCOUNT
- DMAX
✓ Correct answer: AVG
Full explanation
The AVG function returns the average value of a numeric column, while SUM returns the total.
Computer ScienceSQL PPSCID: LTP-7782
Which SQL function returns the largest value in a column?
- AMIN
- BCOUNT
- CMAX ✓ Correct answer
- DSUM
✓ Correct answer: MAX
Full explanation
The MAX function returns the largest value in a column, while MIN returns the smallest.
Computer ScienceSQL PPSCID: LTP-7783
In SQL, a subquery is best described as:
- AA deleted query
- BA printed report
- CA database backup
- DA query nested inside another query ✓ Correct answer
✓ Correct answer: A query nested inside another query
Full explanation
A subquery is a query nested inside another query, and its result is used by the outer query.
Computer ScienceSQL PPSCID: LTP-7784
In SQL, the AS keyword is used to:
- AGive a column or table an alias ✓ Correct answer
- BDelete a column
- CSort the results
- DCreate a database
✓ Correct answer: Give a column or table an alias
Full explanation
The AS keyword is used to give a column or table an alias, a temporary name used in the result of the query.
Computer ScienceSQL PPSCID: LTP-7785
In Oracle, the DUAL table is best described as:
- AA table with all user data
- BA one-row dummy table used for calculations ✓ Correct answer
- CA backup table
- DA table of passwords
✓ Correct answer: A one-row dummy table used for calculations
Full explanation
In Oracle the DUAL table is a one-row dummy table used for calculations and for selecting values such as SYSDATE.
Practice these MCQs interactively
← Computer Science MCQs