General SQL XI
1.
In SQL, what is the purpose of the 'UNPIVOT' operator?
Orders the result set in ascending or descending order
Combines the result sets of two SELECT statements, excluding duplicates
Rotates columns into rows based on a specified column or columns
Performs arithmetic operations on the result set
2.
What is the purpose of the SQL keyword 'HAVING' in a SELECT statement?
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
3.
Which SQL function is used to extract the month from a date?
MONTH()
EXTRACT(MONTH FROM date_column)
DATEPART(MONTH, date_column)
TO_MONTH(date_column)
4.
What does the SQL statement 'SELECT TRIM(' SQL ');' do?
Removes leading spaces from the string
Removes both leading and trailing spaces from the string
Removes trailing spaces from the string
Leaves the string unchanged
5.
Which SQL function is used to find the length of a string excluding leading and trailing spaces?
LENGTH()
CHAR_LENGTH()
LEN()
SIZE()
6.
What is the purpose of the SQL keyword 'TOP' in a SELECT statement?
Performs arithmetic operations on the result set
Orders the result set in ascending or descending order
Limits the number of rows returned in the result set
Filters rows based on a condition after the GROUP BY clause
7.
Which SQL statement is used to change the data type of a column in an existing table?
CHANGE COLUMN column_name new_data_type IN table_name;
ALTER TABLE table_name MODIFY COLUMN column_name new_data_type;
MODIFY DATA TYPE column_name new_data_type IN table_name;
ALTER TABLE table_name SET COLUMN column_name new_data_type;
8.
What does the SQL statement 'SELECT AVG(quantity) FROM products WHERE category = 'Electronics';' do?
Counts the total number of products in the 'Electronics' category
Calculates the average quantity of products in the 'Electronics' category
Deletes all rows from the 'Electronics' category in the products table
Updates all rows in the 'Electronics' category in the products table
9.
Which SQL function is used to convert a string to lowercase?
CONVERT_LOWER()
LCASE()
TO_LOWER()
LOWER()
10.
What is the purpose of the SQL keyword 'CASCADE' in a DELETE statement?
Performs arithmetic operations on the result set
Orders the result set in ascending or descending order
Deletes all rows from the child table when a corresponding row in the parent table is deleted
Filters rows based on a condition after the GROUP BY clause
11.
Which SQL statement is used to calculate the total number of rows in a table?
TOTAL ROWS FROM table_name;
COUNT TABLE table_name;
SELECT COUNT(*) FROM table_name;
SUM TABLE table_name;
12.
Which SQL statement is used to delete all rows from a table without removing the table itself?
DELETE FROM table_name;
REMOVE ALL FROM table_name;
TRUNCATE TABLE table_name;
CLEAR TABLE table_name;
13.
What does the term 'Stored Function' refer to in the context of SQL?
A method of searching for data by directly accessing the data pages
A method of sorting the result set
A precompiled set of one or more SQL statements that can be executed and returns a single value
A type of JOIN that retrieves unmatched rows from both tables
14.
Which SQL function is used to find the position of a substring within a string, starting from a specified position?
INSTR()
POSITION()
SUBSTRING_INDEX()
LOCATE()
15.
Which SQL statement is used to add a NOT NULL constraint to an existing column?
CHANGE TABLE table_name SET COLUMN column_name data_type NOT NULL;
ADD CONSTRAINT NOT NULL TO table_name(column_name);
MODIFY TABLE table_name ADD CONSTRAINT NOT NULL(column_name);
ALTER TABLE table_name MODIFY COLUMN column_name data_type NOT NULL;
16.
What does the SQL statement 'SELECT CONCAT(first_name, ' ', last_name) FROM employees;' do?
Updates all rows in the employees table
Counts the total number of employees
Deletes all rows from the employees table
Concatenates the first name and last name of employees into a single string
17.
What is the purpose of the SQL keyword 'INNER JOIN' in a SELECT statement?
Retrieves rows from both tables where there is a match in the specified columns
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
18.
Which SQL statement is used to rename a table?
ALTER TABLE table_name RENAME TO new_table_name;
RENAME TABLE table_name TO new_table_name;
CHANGE TABLE table_name SET NAME new_table_name;
MODIFY TABLE table_name RENAME new_table_name;
19.
What does the term 'Aggregate Function' refer to in the context of SQL?
A function that performs a calculation on a set of values and returns a single value
Sorting data in ascending or descending order
Filtering data based on a condition
Grouping data based on a column
20.
Which SQL statement is used to update multiple columns in a table in a single statement?
ALTER TABLE table_name UPDATE column1 = value1, column2 = value2 WHERE condition;
MODIFY TABLE table_name UPDATE column1 = value1, column2 = value2 WHERE condition;
CHANGE table_name SET column1 = value1, column2 = value2 WHERE condition;
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;