General SQL IX
1.
What does the SQL statement 'SELECT AVG(salary) FROM employees WHERE department = 'IT';' do?
Updates all rows in the 'IT' department in the employees table
Counts the total number of employees in the 'IT' department
Deletes all rows from the 'IT' department in the employees table
Calculates the average salary of employees in the 'IT' department
2.
Which SQL function is used to extract the year from a date?
YEAR()
EXTRACT(YEAR FROM date_column)
DATEPART(YEAR, date_column)
TO_YEAR(date_column)
3.
What is the purpose of the SQL keyword 'UNION ALL' in a SELECT statement?
Combines the result sets of two SELECT statements, including duplicates
Combines the result sets of two SELECT statements, excluding duplicates
Orders the result set in ascending or descending order
Filters rows based on a condition after the GROUP BY clause
4.
Which SQL statement is used to remove a column from an existing table?
DELETE COLUMN column_name IN table_name;
REMOVE COLUMN column_name FROM table_name;
ALTER TABLE table_name DROP COLUMN column_name;
DROP COLUMN column_name IN table_name;
5.
What does the term 'Normalization' refer to in the context of databases?
Organizing data in a database to reduce redundancy and improve data integrity
Sorting data in ascending order
Filtering data based on a condition
Grouping data based on a column
6.
Which SQL function is used to find the total number of rows in a table?
COUNT(*)
TOTAL_ROWS()
ROWS_COUNT()
SUM_ROWS()
7.
In SQL, what is the purpose of the 'HAVING' clause?
Performs arithmetic operations on the result set
Orders the result set in ascending or descending order
Filters the result set based on aggregate conditions after grouping
Groups the result set based on a column
8.
Which SQL statement is used to create an index on a table?
CREATE INDEX index_name ON table_name(column1, column2);
ADD INDEX index_name TO table_name(column1, column2);
INDEX table_name(column1, column2) CREATE index_name;
ALTER TABLE table_name ADD INDEX index_name(column1, column2);
9.
What does the SQL statement 'SELECT * FROM employees ORDER BY salary DESC LIMIT 5;' do?
Retrieves the top 5 highest salaried employees in descending order
Retrieves all employees and orders them by salary in descending order, showing only the top 5
Deletes the top 5 highest salaried employees
Updates the salary of the top 5 highest salaried employees
10.
Which SQL function is used to find the difference between two dates?
DATE_DIFFERENCE()
DIFFDATE()
DATEDIFF()
DATE_DIFF()
11.
What is the purpose of the SQL keyword 'TRANSACTION' in a stored procedure?
Performs arithmetic operations on the result set
Orders the result set in ascending or descending order
Marks the beginning of a transaction block
Filters rows based on a condition after the GROUP BY clause
12.
Which SQL statement is used to grant all privileges to a user on a database?
GRANT ALL PRIVILEGES ON database_name.* TO user_name;
GRANT DATABASE database_name TO user_name WITH ALL PRIVILEGES;
GRANT PERMISSIONS ALL ON user_name TO database_name;
GRANT user_name ALL PRIVILEGES ON database_name.*;
13.
Which SQL function is used to convert a date to a string in a specific format?
FORMAT_DATE()
TO_STRING(date_column, 'format')
CONVERT_DATE(date_column, 'format')
DATE_FORMAT(date_column, 'format')
14.
Which SQL statement is used to revoke a specific privilege from a user?
REMOVE privilege_name FROM table_name FOR user_name;
DENY privilege_name ON table_name TO user_name;
REVOKE privilege_name ON table_name FROM user_name;
DISALLOW privilege_name ON table_name FROM user_name;
15.
Which SQL statement is used to update values in a column based on a condition in the same column?
ALTER table_name SET column1 = value1 WHERE column1 = condition_value;
MODIFY table_name SET column1 = value1 WHERE column1 = condition_value;
CHANGE table_name SET column1 = value1 WHERE column1 = condition_value;
UPDATE table_name SET column1 = value1 WHERE column1 = condition_value;
16.
In SQL, what is the purpose of the 'ROLLBACK' statement in a transaction?
Filters rows based on a condition after the GROUP BY clause
Orders the result set in ascending or descending order
Performs arithmetic operations on the result set
Undoes all changes made during the current transaction
17.
Which SQL function is used to concatenate two or more strings?
COMBINE()
MERGE()
JOIN()
CONCAT()
18.
What is the purpose of the SQL keyword 'CASE' in a SELECT statement?
Filters rows based on a condition after the GROUP BY clause
Orders the result set in ascending or descending order
Performs arithmetic operations on the result set
Performs conditional logic in a SELECT statement
19.
Which SQL statement is used to remove all rows from a table without deleting the table itself?
DELETE FROM table_name;
REMOVE * FROM table_name;
ERASE FROM table_name;
TRUNCATE TABLE table_name;
20.
What is the purpose of the SQL keyword 'UNION' in a SELECT statement?
Orders the result set in ascending or descending order
Combines the result sets of two or more SELECT statements, including duplicates
Performs arithmetic operations on the result set
Filters rows based on a condition after the GROUP BY clause