Data and Analytics SQL and Database Fundamentals 2 — Questions and Answers
Question 1: Which aggregate function returns the total number of rows in a result set?
- SUM()
- AVG()
- COUNT() (Correct answer)
- MAX()
Correct answer: COUNT()
COUNT() returns the number of rows that match the specified condition, or total rows when used with *.
Question 2: What is a foreign key in a relational database?
- A key used for encryption
- A column that references the primary key of another table (Correct answer)
- An index on multiple columns
- A key that stores NULL values
Correct answer: A column that references the primary key of another table
A foreign key establishes a referential link between a column in one table and the primary key of another table.
Question 3: What SQL statement is used to retrieve data from a database?
- INSERT
- UPDATE
- SELECT (Correct answer)
- DELETE
Correct answer: SELECT
SELECT is the SQL DML statement used to query and retrieve data from one or more database tables.
Question 4: Which SQL window function assigns a unique rank to each row within a partition?
- ROW_NUMBER() (Correct answer)
- SUM() OVER
- LAG()
- PARTITION BY
Correct answer: ROW_NUMBER()
ROW_NUMBER() assigns a unique sequential integer to each row within a partition, with no gaps or ties.
Question 5: What does a NULL value represent in a database?
- Zero
- An empty string
- An unknown or missing value (Correct answer)
- A negative number
Correct answer: An unknown or missing value
NULL represents the absence of a value or an unknown value in a database field.
Question 6: What is a view in SQL?
- A physical copy of a table
- A virtual table defined by a stored query (Correct answer)
- A type of database index
- A backup of the database
Correct answer: A virtual table defined by a stored query
A view is a virtual table whose contents are defined by a SELECT query stored in the database.
Which aggregate function returns the total number of rows in a result set?