WorksheetsChallenging SQL Mastery
Total questions: 20
Worksheet time: 15mins
What is the purpose of the SQL GROUP BY clause?
To sort rows based on specified column values.
To join multiple tables into a single result set.
To filter rows that meet certain criteria.
To group rows that have the same values in specified columns and perform aggregate calculations on them.
Which SQL statement is used to extract data from a database?
RETRIEVE
SELECT
FETCH
GET
What does the acronym ACID stand for in database management?
Accuracy, Clarity, Integrity, Reliability
Atomicity, Consistency, Isolation, Durability
Atomicity, Consistency, Isolation, Redundancy
Atomicity, Concurrency, Isolation, Durability
How do you create a new table in SQL?
INSERT INTO table_name (column1, column2);
ALTER TABLE table_name ADD column1 datatype;
CREATE TABLE table_name (column1 datatype, column2 datatype, ...);
DROP TABLE table_name;
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN includes all rows from both tables; LEFT JOIN excludes unmatched rows.
INNER JOIN returns all left rows with NULLs; LEFT JOIN returns only matched right rows.
INNER JOIN returns all rows regardless of matches; LEFT JOIN only returns matched rows.
INNER JOIN returns matched rows only; LEFT JOIN returns all left rows with matched right rows or NULLs.
Which SQL function is used to count the number of rows in a table?
MAX()
SUM()
COUNT()
AVG()
What is a primary key in a database?
A primary key is a unique identifier for a record in a database.
A primary key is a method for data encryption.
A primary key is a collection of related records.
A primary key is a type of database table.
How can you prevent SQL injection attacks?
Disable all database access permissions.
Rely on user input sanitization only.
Use prepared statements and parameterized queries.
Use simple queries without validation.
What is the purpose of the SQL HAVING clause?
To define table relationships in queries.
To limit the number of rows returned.
To sort results before grouping.
To filter aggregated results after grouping.
What is the difference between UNION and UNION ALL?
UNION sorts results; UNION ALL does not sort.
UNION combines tables; UNION ALL separates them.
UNION requires matching columns; UNION ALL does not.
UNION removes duplicates; UNION ALL includes duplicates.
How do you update data in a SQL table?
INSERT INTO table_name VALUES (value1, value2);
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
DELETE FROM table_name WHERE condition;
SELECT column1, column2 FROM table_name;
What is a foreign key?
A foreign key is a unique identifier for a table.
A foreign key is a field in a table that links to the primary key of another table.
A foreign key is a field that stores data types.
A foreign key is a type of database index.
What does the SQL DISTINCT keyword do?
The SQL DISTINCT keyword limits the number of rows returned.
The SQL DISTINCT keyword removes duplicate values from the result set.
The SQL DISTINCT keyword combines multiple rows into one.
The SQL DISTINCT keyword sorts the result set alphabetically.
How can you retrieve unique values from a column in SQL?
SELECT column_name FROM table_name GROUP BY column_name;
SELECT UNIQUE column_name FROM table_name;
SELECT DISTINCT column_name FROM table_name;
SELECT column_name FROM table_name WHERE column_name IS NOT NULL;
What is the purpose of the SQL ORDER BY clause?
To group the results of a query.
To sort the result set of a query.
To filter the results of a query.
To limit the number of results returned.
What is a subquery in SQL?
A subquery is a method to optimize table joins.
A subquery is a type of database index.
A subquery is a nested query within another SQL query.
A subquery is a command to delete records.
How do you delete a record from a SQL table?
DROP table_name WHERE condition;
DELETE table_name SET condition;
DELETE FROM table_name WHERE condition;
REMOVE FROM table_name WHERE condition;
What is normalization in database design?
Normalization in database design is the process of organizing data to minimize redundancy and dependency.
Normalization is the process of increasing data duplication for efficiency.
Normalization involves creating multiple copies of data for backup purposes.
Normalization refers to the method of encrypting data for security.
What is the difference between a clustered and a non-clustered index?
A clustered index sorts and stores the data rows in the table based on the index, while a non-clustered index creates a separate structure to reference the data rows.
A clustered index stores data in a separate file, while a non-clustered index embeds data within the index.
A clustered index can only be created on unique columns, while a non-clustered index can be on any column.
A clustered index is used for faster searches, while a non-clustered index is slower.
How do you implement transactions in SQL?
Use START TRANSACTION, then run SQL queries, and finally SAVE or DISCARD as needed.
Begin with TRANSACTION, execute commands, and then either FINALIZE or ABORT as necessary.
Initiate a TRANSACTION, perform SQL operations, and conclude with END or REVERT as required.
Use BEGIN TRANSACTION, then execute SQL commands, and finally COMMIT or ROLLBACK as needed.
