Font size
WorksheetsSQL Basics MCQ Worksheet (Digitized)
Total questions: 83
Worksheet time: 47mins
What does SQL stand for?
Simple Query Language
Standard Query Logic
Structured Query Language
System Query Link
Which SQL command is used to extract data from a database?
EXTRACT
GET
SELECT
RETRIEVE
Which SQL command is used to update existing data in a database?
MODIFY
UPDATE
ALTER
REVISE
Which SQL command is used to create a new table in a database?
NEW TABLE
INSERT TABLE
MAKE TABLE
CREATE TABLE
Which clause is used in the CREATE TABLE statement to uniquely identify each record?
FOREIGN KEY
UNIQUE
PRIMARY KEY
NOT NULL
Which SQL command is used to add new records to a table?
INSERT NEW
ADD RECORD
INSERT INTO
CREATE RECORD
Which type of command does CREATE TABLE fall under?
DQL (Data Query Language)
DML (Data Manipulation Language)
DDL (Data Definition Language)
TCL (Transaction Control Language)
The statement SELECT * FROM tbl_Employee; retrieves:
Only the first row of data.
All columns and all rows from the table.
Only the primary key column.
Distinct values from the table.
Which keyword is used to return only distinct (different) values in a result-set?
UNIQUE
DIFFERENT
ALL
DISTINCT
Which clause is used to filter records in a SELECT statement?
FILTER BY
WHERE
CONDITION
SELECT IF
Which operator is used for pattern matching in SQL?
EQUALS
MATCHES
LIKE
CONTAINS
What is the correct syntax to delete records from tbl_Student where SProvince is 'Bukidnon'?
DELETE SProvince='Bukidnon' FROM tbl_Student;
REMOVE FROM tbl_Student WHERE SProvince='Bukidnon';
DELETE FROM tbl_Student WHERE SProvince='Bukidnon';
REMOVE tbl_Student WHERE SProvince='Bukidnon';
What will UPDATE tbl_Employee SET Salary = 70000.00 WHERE EmployeeID = 1001; do?
Update the EmployeeID to 1001.
Insert a new record with a Salary of 70000.00.
Change the Salary to 70000.00 for the employee with EmployeeID 1001.
Change all salaries to 70000.00.
To retrieve the LName and City columns from tbl_Employee, the correct syntax is:
SELECT LName, City IN tbl_Employee;
SELECT LName AND City FROM tbl_Employee;
SELECT LName, City FROM tbl_Employee;
GET LName, City FROM tbl_Employee;
If you omit the WHERE clause in an UPDATE statement, what happens?
No records are updated.
An error is generated.
The first record is updated.
All records in the table are updated.
The WHERE clause is typically used with which SQL commands?
SELECT and CREATE TABLE
SELECT, UPDATE, and DELETE
INSERT INTO and SELECT
ALTER TABLE and DROP TABLE
Which keyword is used to sort the result-set in SQL?
SORT BY
ARRANGE BY
GROUP BY
ORDER BY
By default, how does the ORDER BY clause sort the results?
Randomly
Descending (DESC)
Ascending (ASC)
By Primary Key
Which keyword is used to sort the result-set from highest to lowest value?
ASC
DESC
HIGH
LOW
Which logical operator is used to display a record if both of the conditions are TRUE?
OR
NOT
AND
EITHER
Which logical operator is used to display a record if at least one of the conditions is TRUE?
OR
EITHER
NOT
AND
Which logical operator negates a condition (i.e., returns records that do not satisfy the condition)?
NOT
NONE
NEITHER
EXCLUDE
Which operator selects between two values?
IN
RANGE
BETWEEN
LIKE
The SQL query fragment WHERE price IS NULL is used to:
Find records where the price is zero.
Find records where the price column has no assigned value.
Find records where the price is not a number.
Find records where the price has been deleted.
Which SQL function calculates the number of rows in a result set?
COUNT
SUM
NUMBER
LENGTH
Which SQL function calculates the average value of a numeric column?
MEAN
AVG
SUM / COUNT
CALCULATE
The SQL function MAX() is used to find the:
Largest value in the specified column.
Total sum of the column.
Smallest value in the specified column.
The product with the highest quantity.
Which clause is used to group rows that have the same values in specified columns into summary rows?
ORDER BY
GROUP BY
SUM BY
HAVING
Which clause is used to filter the results of an aggregate function (i.e., filtering groups)?
WHERE
FILTER
GROUP WHERE
HAVING
What is the result of the SQL expression (Quantity * Price) in a SELECT statement?
and Price.
Price.
Quantity and Price for each row.
An alias for the result of COUNT(product_id) function.
In the query SELECT Category, COUNT(product_id) AS product_count..., what does product_count represent?
A column in the products table.
An alias for the Category column.
The total number of products across all categories.
An alias for the result of the COUNT(product_id) function.
When should you use HAVING instead of WHERE?
When filtering based on a non-aggregated column.
They are interchangeable and can be used for any filter.
When filtering based on the result of an aggregate function.
HAVING is a legacy command and should not be used.
What is the correct way to calculate a column alias called MonthlySalary as Salary divided by Months?
SELECT Salary / Months AS MonthlySalary
SELECT Salary, Months / MonthlySalary
SELECT (Salary / Months) = MonthlySalary
SELECT MonthlySalary = Salary / Months
What is the primary purpose of the SQL UNION clause?
To sort the data from
To combine rows from
To insert new data into
To create a new
What is the purpose of the JOIN clause in SQL?
to combine rows from two or more tables based on a related column.
to retrieve data from multiple tables simultaneously.
to filter records from two existing tables.
Which type of join returns only the rows that have matching values in both tables?
LEFT JOIN
RIGHT JOIN
INNER JOIN
Which type of join returns all records from the left table, and the matched records from the right table, with NULL for the right side if there is no match?
RIGHT JOIN
LEFT JOIN
INNER JOIN
What is the primary goal of database normalization?
To eliminate data redundancy and anomalies.
To increase the speed of query execution.
To ensure all tables have the same number of columns.
What is SQL?
A relational database management system
A programming language for web development
A programming language for storing and processing information in a relational database
A tool for graphical database design
Where is data stored in SQL?
Files
Tables
Arrays
Objects
What does the CREATE DATABASE statement do?
Deletes a database
Creates a new SQL database
Modifies a database
Displays the structure of a database
What keyword is used to sort data in SQL?
GROUP BY
SORT
FILTER
ORDER BY
What is an algorithm?
A type of database
A programming language
A type of data model
A sequence of instructions for solving a problem
Why are primary keys important in databases?
To store large amounts of data
To uniquely identify each entity
To sort data
To create relationships between databases
What is the purpose of the SELECT statement?
To delete records
To insert records
To select data from a database
To update existing records
How does the NOT operator work in SQL?
It includes all conditions that are true
It excludes records matching the specified conditions
It sorts data in descending order
It combines multiple conditions
When should you use INNER JOIN?
When combining records with matching values in both tables
When including all records from the left table
When including all records from the right table
When including all records from both tables
What does the COUNT() function return?
The total sum of numeric values
The average of numeric values
The number of rows matching a specified criterion
The maximum value in a column
What would be the result of SELECT * FROM Customers?
Deletes all customers from the database
Updates customer records
Selects all columns and rows from the Customers table
Counts the total number of customers
How would you insert a new record into a table?
Use the SELECT INTO statement
Use the INSERT INTO statement
Use the UPDATE statement
Use the DELETE statement
What happens when you use LEFT JOIN?
Only matching records are returned
All records from the right table are returned, and matching records from the left table
All records from both tables are returned
All records from the left table are returned, and matching records from the right table
How do you compute the total price in a table?
Use the AVG() function
Use the SUM() function
Use the COUNT() function
Use the MAX() function
Which SQL statement modifies existing records?
DELETE
INSERT INTO
UPDATE
SELECT
Why might a composite attribute be subdivided into smaller parts?
To better represent its constituent data elements
To simplify storage requirements
To reduce redundancy
To create relationships between tables
How do ER diagrams help in database design?
They provide a graphical representation of data relationships
They execute queries
They optimize database performance
They store records
When is a FULL OUTER JOIN appropriate?
To return only matching records between two tables
To return all records from both tables regardless of matching
To exclude records without matches
To return records from one table only
What does a derived attribute indicate?
A primary key attribute
An attribute with multiple values
A value calculated from other attribute values
An attribute unrelated to other data
How does the WHERE clause refine SQL queries?
By grouping data
By defining the conditions for data selection
By limiting the number of returned rows
By ordering results alphabetically
Why should databases avoid redundancy?
To minimize storage costs and improve data integrity
To enhance readability
To simplify data retrieval
To make databases easier to understand
How do you determine the most efficient join for a query?
By examining the tables’ attributes and relationships
By always using INNER JOIN
By testing each join type
By using trial-and-error
Which condition is better for filtering rows: WHERE or HAVING?
HAVING should always be used
To minimize storage costs and improve data integrity
Both can be used interchangeably
WHERE for numeric columns, HAVING for text columns
What is the impact of using NULL values in joins?
It creates an error
It guarantees better performance
It excludes certain rows unless handled explicitly
It automatically matches all rows
When is the CASE expression useful?
For modifying existing data
For creating new tables
For updating database schemas
For applying conditional logic in a query
Design a query to display the product names and their suppliers from two tables.
Use SELECT and INNER JOIN
Use INSERT INTO
Use DELETE and DROP
Use CASE and HAVING
How would you structure a query to calculate the average price of dairy products?
Use SELECT and GROUP BY
Use AVG() with a WHERE condition for category
Use SUM() and COUNT()
Use MAX() for the price column
When creating a table, how do you define its schema?
By specifying columns and their data types
By importing data
By writing SELECT statements
By executing DROP statements
What steps are necessary for writing a join between PRODUCTS and SUPPLIERS?
Identify foreign keys and use the JOIN statement
Use SELECT * without conditions
Update both tables beforehand
Use only LEFT JOIN
How can you create a normalized database schema?
By creating tables without relationships
By reducing redundancy and ensuring data dependencies
By avoiding primary keys
By using a single table for all data
The DDL command used to completely remove a table and all its data from the database.
(a)
The clause used in a SELECT statement to filter records, extracting only those that fulfill a specified condition.
(a)
The standard of the American National Standards Institute (ANSI) that SQL became in 1986.
(a)
The SQL command used to add new rows (records) into an existing table.
(a)
The type of join that returns only the rows that have matching values in both the left and right tables.
(a)
A table is in this Normal Form when it is in 1NF, and all non-key attributes are fully dependent on the entire primary key (eliminating partial dependencies).
(a)
The step of normalization addresses no repeating groups (i.e., multiple columns storing the same type of data, or multiple values in one cell)
(a)
It occurs when a non-key attribute is dependent on another non-key attribute, which in turn depends on the primary key (Key → Non-Key A → Non-Key B).
(a)
The database contains two tables: Employees and Departments. To retrieve a result set that includes only employees who have an assigned department and only departments that have at least one employee, which SQL query is correct?
SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees LEFT JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees CROSS JOIN Departments;
You need to generate a report showing all employees and their respective department names. Employees who have not yet been assigned a department must still appear in the report, with a NULL value for the department name. Which join is appropriate?
SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees LEFT JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
SELECT * FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.DeptID;
A table named Projects contains a ProjectLeadID (a foreign key referencing Employees.EmployeeID). Which query correctly returns a list of all employees and the details of any projects they lead, including employees who lead no projects?
SELECT * FROM Employees, Projects WHERE Employees.EmployeeID = Projects.ProjectLeadID;
SELECT * FROM Employees LEFT JOIN Projects ON Employees.EmployeeID = Projects.ProjectLeadID;
SELECT * FROM Employees INNER JOIN Projects ON Employees.EmployeeID = Projects.ProjectLeadID;
SELECT * FROM Employees RIGHT JOIN Projects ON Employees.EmployeeID = Projects.ProjectLeadID;
Which of the following SQL CASE expressions correctly categorizes prices from a Products table into 'High' (price> 100), 'Medium' (price between 50 and 100), or 'Low' (price <= 50)?
SELECT ProductName, CASE WHEN Price > 100 THEN 'High' WHEN Price BETWEEN 50 AND 100 THEN 'Medium' ELSE 'Low' END AS PriceCategory FROM Products;
SELECT ProductName, CATEGORIZE(Price, 'High', 'Medium', 'Low') FROM Products;
SELECT ProductName, CASE Price WHEN > 100 THEN 'High' WHEN 50 TO 100 THEN 'Medium' ELSE 'Low' END AS PriceCategory FROM Products;
SELECT ProductName, CASE WHEN Price > 100 THEN 'High' ELSE 'Medium' WHEN Price <= 50 THEN 'Low' END AS PriceCategory FROM Products;
In a Customers table, if the Country column is NULL, the report should display 'Unknown'. If the Country is 'USA', it should display 'Domestic'. For all other countries, it should display 'International'. Which of the following correctly handles the NULL value?
CASE WHEN Country = NULL THEN 'Unknown' WHEN Country = 'USA' THEN 'Domestic' ELSE 'International' END
CASE WHEN Country = 'USA' THEN 'Domestic' WHEN Country IS NULL THEN 'Unknown' ELSE 'International' END
CASE Country WHEN NULL THEN 'Unknown' WHEN 'USA' THEN 'Domestic' ELSE 'International' END
CASE WHEN Country IS NULL THEN 'Unknown' WHEN Country = 'USA' THEN 'Domestic' ELSE 'International' END
You are using the 'simple' CASE expression to check the value of the Status column. Which of the following code snippets correctly uses the 'simple' CASE expression structure?
CASE (Status) AS StatusCheck WHEN 'Active' THEN 1 ELSE 0 END
CASE Status WHEN 'Active' THEN 1 WHEN 'Inactive' THEN 0 ELSE 0 END
CASE WHEN Status = 'Active' THEN 1 WHEN Status = 'Inactive' THEN 0 END
CASE 'Active' THEN 1 ELSE 0 WHEN 'Inactive' THEN 0 END
The primary role of the ELSE clause in a SQL CASE expression is to:
Handle any syntax errors that occur during the evaluation of the WHEN clauses.
Provide an optional condition to execute a subquery if the CASE expression is computationally expensive.
Specify the condition that must be met if all preceding WHEN conditions are false.
Define a default return value for the expression if none of the preceding WHEN conditions are satisfied.
