-
web.groovymark@gmail.com
- October 25, 2024
Question 01
Which SQL clause is used to sort query results in descending order?
a) GROUP BY
b) ORDER BY DESC
c) LIMIT
d) WHERE
Correct Answer: b) ORDER BY DESC
Explanation: The ORDER BY DESC clause sorts the query results in descending order by the specified column(s).
Question 02
In a relational database, which data type would be most suitable for storing a large textual document?
a) VARCHAR
b) BLOB
c) TEXT
d) CHAR
Correct Answer: c) TEXT
Explanation: The TEXT data type is suitable for storing large textual data in a relational database.
Question 03
Which SQL keyword ensures that all values in a column are unique across all rows in a table?
a) DISTINCT
b) UNIQUE
c) INDEX
d) PRIMARY KEY
Correct Answer: b) UNIQUE
Explanation: The UNIQUE keyword ensures that all values in a column are distinct, preventing duplicate entries in that column.
Question 04
Which function in SQL returns the number of non-NULL rows in a result set?
a) SUM()
b) AVG()
c) COUNT()
d) MAX()
Correct Answer: c) COUNT()
Explanation: The COUNT() function returns the number of non-NULL rows in a result set.
Question 05
In SQL, which operator is used to check if a value exists in a specified set of values?
a) LIKE
b) IN
c) EXISTS
d) BETWEEN
Correct Answer: b) IN
Explanation: The IN operator checks if a value exists in a list of specified values.
Question 06
Which type of key allows NULL values and is used to create links between tables?
a) Foreign Key
b) Primary Key
c) Composite Key
d) Unique Key
Correct Answer: a) Foreign Key
Explanation: A Foreign Key allows NULL values and is used to establish relationships between tables by referencing the primary key in another table.
Question 07
Which SQL keyword removes duplicate rows from the result of a SELECT statement?
a) UNIQUE
b) DISTINCT
c) GROUP BY
d) ORDER BY
Correct Answer: b) DISTINCT
Explanation: The DISTINCT keyword removes duplicate rows from the result of a SELECT query, returning only unique rows.
Question 08
Which SQL function is used to convert all characters in a string to uppercase?
a) UPPER()
b) LOWER()
c) TRIM()
d) SUBSTRING()
Correct Answer: a) UPPER()
Explanation: The UPPER() function converts all characters in a string to uppercase in SQL.
Question 09
Which type of index is optimized for queries that check whether values fall within a range?
a) Hash Index
b) Bitmap Index
c) B-Tree Index
d) Dense Index
Correct Answer: c) B-Tree Index
Explanation: B-Tree indexes are optimized for queries that involve range-based searches, as they allow efficient traversal through ordered data.
Question 10
In a database, which term describes the combination of multiple columns to form a single key that uniquely identifies each row?
a) Composite Key
b) Primary Key
c) Foreign Key
d) Unique Key
Correct Answer: a) Composite Key
Explanation: A Composite Key is a combination of two or more columns that together uniquely identify each row in a table.
Question 11
Which aggregate function in SQL is used to return the highest value in a column?
a) MAX()
b) MIN()
c) SUM()
d) AVG()
Correct Answer: a) MAX()
Explanation: The MAX() function returns the highest value from a specified column in SQL.
Question 12
Which SQL clause groups rows that have the same values in specified columns?
a) GROUP BY
b) ORDER BY
c) HAVING
d) WHERE
Correct Answer: a) GROUP BY
Explanation: The GROUP BY clause groups rows that share the same values in the specified columns, often used with aggregate functions.
Question 13
Which SQL command is used to create a new user account with specific privileges?
a) GRANT
b) CREATE USER
c) ALTER USER
d) INSERT
Correct Answer: b) CREATE USER
Explanation: The CREATE USER command is used to create a new database user account, which can then be granted specific privileges.
Question 14
Which clause is used in SQL to return only unique values from a column?
a) UNIQUE
b) DISTINCT
c) ORDER BY
d) GROUP BY
Correct Answer: b) DISTINCT
Explanation: The DISTINCT clause ensures that only unique values are returned from the specified column, removing duplicates.
Question 15
Which SQL clause is used to combine the results of two SELECT statements?
a) UNION
b) JOIN
c) INTERSECT
d) CROSS JOIN
Correct Answer: a) UNION
Explanation: The UNION clause is used to combine the results of two SELECT queries into a single result set, excluding duplicates.
Question 16
Which SQL keyword is used to limit the number of rows returned by a query?
a) LIMIT
b) TOP
c) OFFSET
d) ROWCOUNT
Correct Answer: a) LIMIT
Explanation: The LIMIT keyword restricts the number of rows returned by a SELECT query to a specified number.
Question 17
Which type of constraint ensures that the values in a column must satisfy a specified condition?
a) FOREIGN KEY
b) PRIMARY KEY
c) CHECK
d) UNIQUE
Correct Answer: c) CHECK
Explanation: The CHECK constraint ensures that the values in a column meet a specified condition or rule.
Question 18
Which type of database relationship is created when a table contains a reference to itself?
a) One-to-One
b) One-to-Many
c) Many-to-Many
d) Self-Join
Correct Answer: d) Self-Join
Explanation: A Self-Join occurs when a table is joined to itself, often used to compare rows within the same table.
Question 19
Which clause in SQL is used to apply a filter to grouped data?
a) WHERE
b) HAVING
c) LIMIT
d) ORDER BY
Correct Answer: b) HAVING
Explanation: The HAVING clause is used to apply conditions to groups created by the GROUP BY clause, filtering the results after grouping.
Question 20
What is the purpose of an index in a relational database?
a) To store data permanently
b) To create relationships between tables
c) To speed up data retrieval
d) To enforce data integrity
Correct Answer: c) To speed up data retrieval
Explanation: Indexes are used to improve the performance of queries by allowing the database to locate and retrieve rows more quickly.