NEW
Font size
WorksheetsSQL Mastery Challenge
Total questions: 40
Worksheet time: 20mins
What is the purpose of a JOIN in SQL?
To combine rows from two or more tables based on a related column.
To create a new table in the database.
To update existing records in a table.
To delete rows from a table.
Explain the difference between INNER JOIN and LEFT JOIN.
INNER JOIN returns matching rows from both tables; LEFT JOIN returns all rows from the left table and matched rows from the right table.
INNER JOIN and LEFT JOIN are identical in functionality and output.
INNER JOIN returns all rows from the left table; LEFT JOIN returns only unmatched rows from the right table.
INNER JOIN returns all rows from both tables; LEFT JOIN returns only matching rows.
What is a subquery and when would you use one?
A subquery is a nested query used to retrieve data based on another query's results.
A subquery is a type of database index.
A subquery is a method for data encryption.
A subquery is used to create new tables.
How can you optimize a query using indexing?
Use a single index for all columns to reduce complexity.
Create indexes on frequently queried columns to improve query performance.
Create indexes on rarely queried columns to save space.
Avoid using indexes as they slow down all queries.
What are the types of indexes available in SQL?
Tree, Hashmap, Bitmap, Text
B-tree, Hash, Bitmap, XML, Spatial
B-tree, Hash, Bitmap, Full-text, Graph
B-tree, Hash, Bitmap, Full-text, Spatial
How does indexing affect the performance of data retrieval?
Indexing has no impact on query performance.
Indexing slows down data retrieval by increasing search time.
Indexing significantly enhances data retrieval speed by reducing search time and improving query performance.
Indexing complicates data retrieval processes.
What is the purpose of the Data Manipulation Language (DML)?
To define the structure of a database.
To create new database tables.
The purpose of DML is to manipulate data in a database.
To manage user permissions in a database.
List the main DML commands in SQL.
SHOW, DESCRIBE, EXPLAIN, RENAME
FETCH, JOIN, MERGE, INDEX
INSERT, UPDATE, DELETE, SELECT
CREATE, ALTER, DROP, TRUNCATE
How do you insert data into a table using SQL?
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
SELECT * FROM table_name;
DELETE FROM table_name WHERE condition;
UPDATE table_name SET column1 = value1;
What is the syntax for updating records in a SQL table?
SELECT * FROM table_name WHERE condition;
INSERT INTO table_name VALUES (value1, value2);
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
DELETE FROM table_name WHERE condition;
Explain the use of the DELETE statement in SQL.
The DELETE statement is used to create a new table in SQL.
The DELETE statement is used to add new rows to a table in SQL.
The DELETE statement is used to update existing rows in a table in SQL.
The DELETE statement is used to remove rows from a table in SQL.
What are aggregate functions in SQL?
Aggregate functions in SQL return multiple values from a set of data.
Aggregate functions in SQL are only applicable to string values.
Aggregate functions in SQL are functions that perform calculations on a set of values and return a single value.
Aggregate functions in SQL are used to modify data types.
Give examples of commonly used aggregate functions.
ADD, SUBTRACT, DIVIDE
TOTAL, MEAN, RANGE
FIRST, LAST, AVERAGE
SUM, AVG, COUNT, MAX, MIN
How do you use the GROUP BY clause with aggregate functions?
Use GROUP BY without any aggregate functions.
You can only use GROUP BY with numeric data types.
Use SELECT with aggregate functions and GROUP BY to group results.
GROUP BY is only for sorting data.
What is a stored procedure in SQL?
A stored procedure is a precompiled collection of SQL statements that can be executed as a single unit.
A stored procedure is a temporary table used for data storage.
A stored procedure is a command to create a new database.
A stored procedure is a type of database index.
How do you create a stored procedure in SQL?
CREATE TABLE table_name (columns);
ALTER PROCEDURE procedure_name (parameters);
CREATE FUNCTION function_name (parameters) BEGIN SQL_statements; END;
CREATE PROCEDURE procedure_name (parameters) BEGIN SQL_statements; END;
What are the advantages of using stored procedures?
Increased complexity in code management
Slower execution times
Reduced data security risks
Advantages of using stored procedures include improved performance, enhanced security, easier maintenance, and data integrity enforcement.
How can you pass parameters to a stored procedure?
You can only pass parameters as global variables.
You can pass parameters by defining them in the procedure and providing values during the call.
Stored procedures do not accept any parameters.
Parameters can only be passed as JSON objects.
What is the difference between a function and a stored procedure?
A stored procedure returns a value; a function performs actions without returning a value.
A function is always faster than a stored procedure in execution.
A function can only be used in SQL queries; a stored procedure cannot.
A function returns a value; a stored procedure performs actions without returning a value.
How do you handle errors in stored procedures?
Use TRY...CATCH blocks for error handling.
Use a global error handler instead of TRY...CATCH.
Log errors to a file without handling them.
Ignore errors and continue execution.
A primary key can be NULL in the table? TRUE or FALSE
TRUE
FALSE
7. _________ helps to set a limit value placed for a field.
DEFAULT Constraint
Primary Key Constraint
Check Constraint
TABLE CONSTRAINT
6. ___________ which helps to uniquely identify a record.
Primary key Constraint
Unique Constraint
Default constraint
Check constraint
5. ___________ constraint ensures that no two rows have the same value in the specified columns.
Primary Key
Unique
Default
Check
Which option is not the command of DML ?
insert
update
alter
delete
A _____ is a place where we can used to store huge amounts of structured data from different databases in a one place.
database
data lake
cloud
data warehouse
Is images and videos being the example of the Structured data?
Yes
No
Less than or equal to?
>=
=>
=<
<=
An SQL command used to add record in a table.
Insert
Create
Update
Add
Which is not the sub language of SQL?
DDL
DML
DCL
PCL
Which would show all fields from the Pupils table?
SELECT * FROM Pupils
SELECT Name, Form FROM Pupils
SELECT * FROM *
SELECT * FROM Forms
With SQL, how do you select all the records from a table named "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen"?
SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'
SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons
With SQL, how do you select all the records from a table named "Persons" where the "FirstName" is "Peter" and the "LastName" is "Jackson"?
SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'
SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'
SELECT FirstName='Peter', LastName='Jackson' FROM Persons
With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"?
SELECT * FROM Persons WHERE FirstName='a'
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
SELECT * FROM Persons WHERE FirstName='%a%'
SELECT * FROM Persons WHERE FirstName LIKE '%a'
With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter"?
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
SELECT [all] FROM Persons WHERE FirstName='Peter'
SELECT * FROM Persons WHERE FirstName='Peter'
SELECT * FROM Persons WHERE FirstName<>'Peter'
With SQL, how do you select all the columns from a table named "Persons"?
SELECT [all] FROM Persons
SELECT Persons
SELECT * FROM Persons
SELECT *.Persons
To remove duplicate rows from the results of an SQL SELECT statement, the ________ qualifier specified must be included
ONLY
UNIQUE
DISTINCT
SINGLE
The command to eliminate a table from a database is:
REMOVE TABLE CUSTOMER;
DROP TABLE CUSTOMER;
DELETE TABLE CUSTOMER;
UPDATE TABLE CUSTOMER;
The command to remove rows from a table ‘CUSTOMER’ is:
REMOVE FROM CUSTOMER …
DROP FROM CUSTOMER …
DELETE FROM CUSTOMER WHERE …
UPDATE FROM CUSTOMER …
