50 multiple-choice questions with answers and detailed explanations. Untimed — choose an answer to check it instantly.
0/50 answered0 correct
Question 1 of 50
Which SQL clause is used to retrieve data from a database table?
Correct answer: B) SELECT
Explanation: The SELECT clause is used in SQL to query and retrieve data from a database table. INSERT adds new rows, DELETE removes rows, and UPDATE modifies existing rows.
Question 2 of 50
In a relational database, what is a tuple?
Correct answer: B) An ordered collection of elements
Explanation: In a relational database, a tuple represents a single row in a table and is an ordered collection of elements. Unordered collections are sets, key-value pairs are used in NoSQL databases, and relationships between tables are managed through keys.
Question 3 of 50
What SQL command is used to delete a table from a database?
Correct answer: C) DROP
Explanation: The DROP command is used to completely remove a table from the database. DELETE removes rows from a table, TRUNCATE clears all rows but keeps the table structure, and ALTER modifies the structure of a table.
Question 4 of 50
Which relational operation eliminates one or more columns of a table?
Correct answer: B) PROJECT
Explanation: The PROJECT operation is used to select specific columns of a table, eliminating the others. SELECT retrieves rows, JOIN combines tables based on a condition, and UNION merges two tables into one.
Question 5 of 50
Which SQL keyword is used to rename a column or table in a query result?
Correct answer: A) AS
Explanation: The AS keyword is used to rename columns or tables in SQL query results. FROM specifies the table, RENAME is not used in query results, and ALIAS is a general term for renaming but not a keyword.
Question 6 of 50
In SQL, what does the GROUP BY clause do?
Correct answer: A) Groups rows that have the same values in specified columns
Explanation: The GROUP BY clause groups rows that share values in specified columns, often used with aggregate functions. ORDER BY sorts the result set, WHERE filters rows, and DISTINCT removes duplicates.
Question 7 of 50
Which of the following is a binary operation in relational algebra?
Correct answer: C) PRODUCT
Explanation: The PRODUCT operation in relational algebra combines all rows from two tables. SELECT and PROJECT are unary operations, while RENAME changes table or column names.
Question 8 of 50
Which of the following SQL clauses is used to filter records?
Correct answer: A) WHERE
Explanation: The WHERE clause is used to filter records based on a specified condition. SELECT retrieves data, GROUP BY groups rows, and ORDER BY sorts the result set.
Question 9 of 50
What is a primary key in a relational database?
Correct answer: A) A column that contains unique values for each row
Explanation: A primary key uniquely identifies each row in a table. It cannot contain duplicate values, while foreign keys refer to other tables, and binary data is not related to primary keys.
Question 10 of 50
In SQL, which command is used to create a new table?
Correct answer: B) CREATE TABLE
Explanation: The CREATE TABLE command is used to create a new table in a database. CREATE DATABASE creates a new database, ALTER TABLE modifies an existing table, and INSERT INTO adds data to a table.
Question 11 of 50
Which of the following aggregate functions counts the number of rows in a table?
Correct answer: B) COUNT()
Explanation: The COUNT() function returns the number of rows in a table. SUM() adds numeric values, AVG() calculates the average, and MAX() returns the maximum value.
Question 12 of 50
What is the role of the FOREIGN KEY in a relational database?
Correct answer: B) Links rows from two tables based on a related column
Explanation: A foreign key links rows in two tables by referencing a primary key in another table. A primary key uniquely identifies rows, while binary data and temporary tables are unrelated to foreign keys.
Question 13 of 50
Which SQL statement is used to change data in an existing row?
Correct answer: C) UPDATE
Explanation: The UPDATE statement is used to modify existing data in a row. INSERT adds new rows, DELETE removes rows, and SELECT retrieves data without modification.
Question 14 of 50
What does the HAVING clause do in SQL?
Correct answer: A) Filters rows based on aggregate functions
Explanation: The HAVING clause filters rows after aggregation, commonly used with GROUP BY. WHERE filters rows before aggregation, and ORDER BY sorts rows. DISTINCT removes duplicate rows.
Question 15 of 50
Which of the following is a volatile memory type?
Correct answer: C) RAM
Explanation: RAM is volatile memory, meaning its data is lost when power is turned off. Hard drives, flash memory, and magnetic tapes are non-volatile, retaining data without power.
Question 16 of 50
In the context of databases, what is normalization?
Correct answer: B) The process of organizing data to reduce redundancy
Explanation: Normalization organizes data in a way that reduces redundancy and ensures data integrity. It is unrelated to query speed, storage capacity, or data filtering.
Question 17 of 50
What is a database transaction?
Correct answer: B) A sequence of one or more SQL operations treated as a single unit
Explanation: A transaction in a database is a sequence of operations performed as a single logical unit. Transactions ensure data integrity and consistency. Queries and filtering are individual operations, while query optimization is unrelated.
Question 18 of 50
Which of the following is an example of an aggregate function?
Correct answer: B) COUNT()
Explanation: COUNT() is an aggregate function that returns the number of rows in a result set. IFNULL() handles null values, CONCAT() concatenates strings, and SUBSTRING() extracts a portion of a string.
Question 19 of 50
What does the JOIN clause do in SQL?
Correct answer: A) Combines rows from two or more tables based on a related column
Explanation: The JOIN clause combines rows from different tables based on a related column. It does not delete rows, rename columns or tables, or group rows.
Question 20 of 50
Which type of join returns only matching rows from both tables?
Correct answer: D) INNER JOIN
Explanation: An INNER JOIN returns only rows that have matching values in both tables. LEFT JOIN returns all rows from the left table, RIGHT JOIN returns all rows from the right table, and FULL JOIN returns all rows from both tables.
Question 21 of 50
What does the UNION operator do in SQL?
Correct answer: A) Combines the result sets of two queries and removes duplicates
Explanation: The UNION operator combines the result sets of two queries and removes duplicate rows. If duplicates should be included, the UNION ALL operator is used. Grouping and combining rows from tables are done by other SQL operations.
Question 22 of 50
What is the purpose of the ROLLBACK command in SQL?
Correct answer: B) Reverts changes made during a transaction
Explanation: The ROLLBACK command is used to undo changes made during a transaction. COMMIT saves changes, while DELETE and UPDATE perform specific modifications on data.
Question 23 of 50
In SQL, which operator is used to select values within a range?
Correct answer: B) BETWEEN
Explanation: The BETWEEN operator is used to select values within a specific range. LIKE is used for pattern matching, IN is used to check if a value is within a list, and EXISTS checks for the existence of rows in a subquery.
Question 24 of 50
Which of the following SQL statements is used to grant privileges to a user?
Correct answer: A) GRANT
Explanation: The GRANT statement is used to provide specific privileges to a user in SQL. REVOKE removes those privileges, ALTER modifies database objects, and INSERT adds new data.
Question 25 of 50
In a relational database, what ensures referential integrity?
Correct answer: B) Foreign Key
Explanation: A foreign key ensures referential integrity by linking two tables together. It ensures that a referenced value in another table exists. A primary key ensures uniqueness, while an index speeds up queries and a trigger executes an action automatically based on a condition.
Question 26 of 50
Which SQL function is used to return the length of a string?
Correct answer: B) LENGTH()
Explanation: The LENGTH() function returns the number of characters in a string. SUBSTRING() extracts a part of the string, CONCAT() joins strings, and TRIM() removes leading and trailing spaces from a string.
Question 27 of 50
Which of the following keywords is used in SQL to sort results in descending order?
Correct answer: B) ORDER BY DESC
Explanation: The ORDER BY DESC keyword sorts the result set in descending order. ORDER BY ASC sorts in ascending order, GROUP BY groups rows based on column values, and HAVING filters rows based on aggregate functions.
Question 28 of 50
In a relational database, what type of join returns all rows from both tables, including non-matching rows?
Correct answer: C) FULL JOIN
Explanation: A FULL JOIN returns all rows from both tables, with NULLs for non-matching rows. INNER JOIN returns only matching rows, LEFT JOIN returns all rows from the left table, and CROSS JOIN returns the Cartesian product of two tables.
Question 29 of 50
What does the TRUNCATE command do in SQL?
Correct answer: B) Removes all rows from a table but keeps the table structure
Explanation: The TRUNCATE command deletes all rows from a table but keeps the structure intact. DELETE can remove specific rows based on conditions, while DROP deletes the table itself.
Question 30 of 50
What is the purpose of the COMMIT command in SQL?
Correct answer: A) Saves changes made to the database during a transaction
Explanation: The COMMIT command is used to save all changes made during a transaction to the database. ROLLBACK undoes changes, while DELETE and ALTER modify specific aspects of the data or table.
Question 31 of 50
Which clause in SQL is used to filter groups created by the GROUP BY clause?
Correct answer: B) HAVING
Explanation: The HAVING clause filters groups created by the GROUP BY clause. WHERE filters rows before grouping, ORDER BY sorts the result set, and DISTINCT removes duplicates.
Question 32 of 50
What does the EXISTS operator do in SQL?
Correct answer: A) Returns TRUE if a subquery returns at least one row
Explanation: The EXISTS operator returns TRUE if the subquery returns one or more rows. If no rows are returned, it returns FALSE. It is often used to check for the presence of records.
Question 33 of 50
In SQL, which keyword is used to combine rows from two or more tables without any conditions?
Correct answer: B) CROSS JOIN
Explanation: A CROSS JOIN combines every row from two or more tables without any conditions, resulting in the Cartesian product of the tables. INNER JOIN, LEFT JOIN, and RIGHT JOIN require conditions to match rows from the tables.
Question 34 of 50
Which SQL function is used to remove leading and trailing spaces from a string?
Correct answer: C) TRIM()
Explanation: The TRIM() function removes leading and trailing spaces from a string. LENGTH() returns the number of characters in a string, SUBSTRING() extracts a portion of a string, and CONCAT() joins two or more strings together.
Question 35 of 50
What is the default sorting order when using the ORDER BY clause in SQL?
Correct answer: A) Ascending
Explanation: The default sorting order for the ORDER BY clause in SQL is ascending. To sort in descending order, you would use the DESC keyword. Sorting is not random, and alphabetical order is only relevant when sorting string data in ascending or descending order.
Question 36 of 50
In SQL, what type of join selects all records from the left table and the matched records from the right table?
Correct answer: C) LEFT JOIN
Explanation: A LEFT JOIN selects all records from the left table and the matched records from the right table. If there is no match, NULL values are returned for columns from the right table. RIGHT JOIN does the opposite, INNER JOIN selects only matching records, and FULL JOIN returns all records from both tables.
Question 37 of 50
Which SQL statement is used to add a new column to an existing table?
Correct answer: B) ALTER TABLE
Explanation: The ALTER TABLE statement is used to add a new column to an existing table. ADD COLUMN is not a valid standalone SQL command, CREATE TABLE is used to create a new table, and INSERT INTO adds new rows to a table.
Question 38 of 50
Which SQL function is used to concatenate two or more strings?
Correct answer: A) CONCAT()
Explanation: The CONCAT() function is used to join two or more strings together. SUBSTRING() extracts part of a string, LENGTH() returns the number of characters in a string, and TRIM() removes leading and trailing spaces.
Question 39 of 50
In SQL, what is a view?
Correct answer: B) A virtual table based on a SQL query
Explanation: A view is a virtual table in SQL, created based on the result of a query. It does not store data itself but retrieves data from the underlying tables. Temporary tables are created using different SQL commands, and views do not store only primary keys or duplicate rows.
Question 40 of 50
Which SQL function is used to return the current date and time?
Correct answer: B) NOW()
Explanation: The NOW() function returns the current date and time in SQL. CURDATE() returns only the current date, DATE() extracts the date part of a timestamp, and TIME() extracts the time part of a timestamp.
Question 41 of 50
Which SQL clause is used to retrieve a specific number of rows from the result set?
Correct answer: A) LIMIT
Explanation: The LIMIT clause is used to specify the number of rows to return from the result set. SELECT retrieves data, ORDER BY sorts the result set, and GROUP BY groups rows based on column values.
Question 42 of 50
What is the purpose of the INDEX in SQL?
Correct answer: C) To improve the performance of queries
Explanation: An index in SQL is used to improve the performance of queries by allowing the database to find rows more quickly. It does not store data or create new tables but enhances the efficiency of data retrieval.
Question 43 of 50
Which SQL function is used to extract the year from a date?
Correct answer: A) YEAR()
Explanation: The YEAR() function extracts the year from a date. DATE() is used to format a date, EXTRACT() extracts parts of a date but requires specifying the unit, and SUBSTRING() extracts portions of a string.
Question 44 of 50
What type of data structure is typically used for fast data lookup in databases?
Correct answer: B) Hash table
Explanation: A hash table is commonly used for fast data lookup in databases due to its ability to map keys to values efficiently. Linked lists, stacks, and queues are used for different purposes and do not provide the same efficiency for lookups.
Question 45 of 50
What is the purpose of the ALTER statement in SQL?
Correct answer: A) To add, modify, or delete columns in an existing table
Explanation: The ALTER statement is used to modify the structure of an existing table, including adding, modifying, or deleting columns. INSERT adds data, DROP removes tables, and SELECT retrieves data.
Question 46 of 50
In SQL, what is the purpose of the HAVING clause?
Correct answer: A) To filter groups of rows after aggregation
Explanation: The HAVING clause is used to filter groups of rows after they have been aggregated, often used with GROUP BY. WHERE is used to filter rows before aggregation, DISTINCT filters duplicates, and JOIN combines rows from multiple tables.
Question 47 of 50
Which SQL operator is used to select rows that match a specified pattern?
Correct answer: B) LIKE
Explanation: The LIKE operator is used to select rows that match a specified pattern. BETWEEN selects values within a range, IN checks if a value is in a list, and EXISTS checks if a subquery returns any rows.
Question 48 of 50
What is the purpose of the DROP command in SQL?
Correct answer: B) To remove a table or database
Explanation: The DROP command is used to remove a table or database from the system. It completely deletes the structure, unlike DELETE, which removes data but retains the table.
Question 49 of 50
Which SQL statement is used to combine the result sets of two or more SELECT statements?
Correct answer: B) UNION
Explanation: The UNION statement is used to combine the result sets of two or more SELECT statements, removing duplicates by default. JOIN combines rows from tables, GROUP BY groups rows, and ORDER BY sorts the result set.
Question 50 of 50
What is the role of the PRIMARY KEY in a relational database?
Correct answer: B) To uniquely identify each row in a table
Explanation: The PRIMARY KEY uniquely identifies each row in a table and ensures that no duplicate values exist. It is crucial for maintaining data integrity, while foreign keys link tables, and sorting is handled by ORDER BY.
Set 1 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).