WorksheetsMastering SQL Commands and Functions
Total questions: 20
Worksheet time: 10mins
What SQL command is used to insert new records into a table?
INSERT
SELECT
DELETE
UPDATE
How do you update existing records in a SQL table?
Use the SQL command: INSERT INTO table_name VALUES (value1, value2);
Use the SQL command: UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
Use the SQL command: DELETE FROM table_name WHERE condition;
Use the SQL command: SELECT * FROM table_name WHERE condition;
What is the purpose of the ALTER TABLE command in SQL?
To modify the structure of an existing table.
To delete an existing table.
To retrieve data from a table.
To create a new table.
Which SQL command is used to delete records from a table?
CLEAR
DELETE
DROP
REMOVE
How can you retrieve records from a table based on specific conditions?
Use SQL UPDATE with SET clause.
Use SQL INSERT to add new records.
Use SQL DELETE to remove records.
Use SQL SELECT with WHERE clause.
What is the purpose of aggregate functions in SQL?
To store data in a database
To define relationships between tables
To create new tables in SQL
The purpose of aggregate functions in SQL is to perform calculations on a set of values and return a single summarized value.
How do you use the ORDER BY clause in a SQL query?
The ORDER BY clause is only applicable to SELECT statements without any conditions.
The ORDER BY clause is used to filter the result set of a query.
The ORDER BY clause is used to sort the result set of a query by one or more columns.
The ORDER BY clause automatically groups the result set by default.
What is the difference between GROUP BY and HAVING clauses?
GROUP BY groups data, while HAVING filters groups based on aggregate conditions.
GROUP BY filters data, while HAVING groups data based on conditions.
GROUP BY is used for sorting data, while HAVING is for selecting specific rows.
GROUP BY and HAVING are interchangeable clauses in SQL.
How do you implement a JOIN query in SQL?
SELECT columns FROM table1 JOIN table2 ON table1.column = table2.column;
SELECT columns FROM table1 INNER JOIN table2;
JOIN table1 AND table2 ON table1.column = table2.column;
SELECT * FROM table1, table2 WHERE table1.column = table2.column;
What are set operators in SQL? Give an example.
An example of a set operator is UNION, which combines the results of two SELECT statements and removes duplicates. For instance: SELECT column1 FROM table1 UNION SELECT column1 FROM table2.
EXCEPT, which returns records from the first SELECT that are not in the second.
INTERSECT, which finds common records between two SELECT statements.
JOIN, which combines rows from two or more tables based on a related column.
What is a nested query in SQL?
A nested query is a type of database index.
A nested query is a single SQL command.
A nested query is a query within another SQL query.
A nested query is a method for optimizing database performance.
What is the purpose of the COMMIT command in SQL?
To delete all records from a table.
To create a new database.
To update existing records in a table.
To save changes made during a transaction.
How do you use ROLLBACK in SQL?
ROLLBACK is used to view the current state of the database.
ROLLBACK is used to undo changes made in a transaction.
ROLLBACK is a command to create a new transaction.
ROLLBACK is used to permanently save changes in a transaction.
What is a SAVEPOINT in SQL?
A SAVEPOINT is a marker in a transaction that allows partial rollback.
A SAVEPOINT is a command to create a new database.
A SAVEPOINT is used to permanently delete records.
A SAVEPOINT is a type of SQL function for data retrieval.
How do you grant user privileges in SQL?
Execute the DELETE command to remove user privileges.
Apply the UPDATE statement to modify user roles.
Use the SELECT statement to retrieve user data.
Use the GRANT statement to assign privileges to users.
What command is used to revoke user privileges in SQL?
BLOCK
REVOKE
DENY
REMOVE
How do you create a view in SQL?
DROP VIEW view_name;
CREATE TABLE view_name AS SELECT column1, column2 FROM table_name;
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;
ALTER VIEW view_name SET column1 = value;
What is an assertion in SQL and how is it implemented?
An assertion in SQL is a type of database index.
An assertion in SQL is a command to delete records.
Assertions in SQL are used to create temporary tables.
An assertion in SQL is a condition that must always be true, implemented using the CREATE ASSERTION statement.
What is the purpose of the DISTINCT keyword in SQL?
To create a new table with unique values.
To remove duplicate rows from the result set.
To sort the result set in ascending order.
To limit the number of rows returned by a query.
What is the purpose of the INDEX in SQL?
To speed up the retrieval of rows from a table.
To enforce data integrity in a database.
To delete records from a table.
To create a backup of the database.
