Sample Questions and Answers
What does the “HAVING” clause do in SQL?
A. Filters records before grouping them.
B. Groups records by specified columns.
C. Filters records after grouping them.
D. Sorts the records in ascending or descending order.
Answer: C
Which of the following is a characteristic of a “relational database”?
A. Data is stored in a hierarchy of records.
B. Data is stored in tables with rows and columns.
C. Data is stored as key-value pairs.
D. Data is stored in graphs of nodes and relationships.
Answer: B
Which of the following is the correct SQL syntax to add a new column to an existing table?
A. ALTER TABLE table_name ADD COLUMN column_name datatype;
B. MODIFY TABLE table_name ADD column_name datatype;
C. CHANGE TABLE table_name ADD column_name datatype;
D. UPDATE TABLE table_name ADD column_name datatype;
Answer: A
In a “many-to-many” relationship, what is typically used to resolve the relationship?
A. A foreign key
B. A join table or junction table
C. A view
D. A trigger
Answer: B
Which of the following SQL keywords is used to remove a table from a database?
A. DELETE
B. DROP
C. TRUNCATE
D. REMOVE
Answer: B
What is the purpose of the “ORDER BY” clause in SQL?
To sort the result set in a specific order.
B. To group records by one or more columns.
C. To limit the number of records returned.
D. To calculate aggregate values for records.
Answer: A
In SQL, what is the default sorting order when using the “ORDER BY” clause?
Ascending (ASC)
B. Descending (DESC)
C. Random
D. No sorting order is applied.
Answer: A
What is a “composite key” in a relational database?
A key that consists of two or more columns to uniquely identify a record.
B. A unique identifier generated by the database.
C. A primary key combined with a foreign key.
D. A key that is automatically generated by the system.
Answer: A
Which of the following is a characteristic of “NoSQL” databases?
They are always relational.
B. They use structured query language (SQL).
C. They are optimized for handling large volumes of unstructured or semi-structured data.
D. They are slower in processing queries compared to relational databases.
Answer: C
Which of the following operations is used to remove all records from a table but keep the table structure intact?
REMOVE
B. DELETE
C. TRUNCATE
D. DROP
Answer: C
In a relational database, which of the following defines the relationships between tables?
Views
B. Foreign keys
C. Triggers
D. Indexes
Answer: B
What does the “JOIN” clause do in SQL?
Combines rows from two or more tables based on a related column.
B. Combines columns from two tables.
C. Groups data into distinct values.
D. Sorts the rows in the result set.
Answer: A
Which of the following is an advantage of using a “view” in SQL?
It stores data permanently in the database.
B. It speeds up the database query execution.
C. It simplifies complex queries by providing an abstraction layer.
D. It automatically updates data in the underlying table.
Answer: C
What does the SQL statement “UPDATE table_name SET column_name = value WHERE condition” do?
It adds new rows to the table.
B. It removes rows from the table.
C. It modifies existing data in the table.
D. It creates a new table based on the specified data.
Answer: C
What is a “transaction” in the context of a relational database?
A command to retrieve data from a database.
B. A series of operations executed as a single unit to ensure consistency and integrity.
C. A function that aggregates values from a table.
D. A temporary structure used to store query results.
Answer: B
What does the “ROLLBACK” command do in SQL?
It commits the transaction and saves changes permanently.
B. It undoes changes made during the current transaction.
C. It deletes all rows from the table.
D. It restarts the current transaction.
Answer: B
Which of the following operations can be performed by “Data Definition Language (DDL)”?
Inserting data into a table.
B. Modifying data in a table.
C. Creating and deleting database objects like tables and indexes.
D. Querying data from a table.
Answer: C
What is the “REFERENCES” keyword used for in SQL?
To specify a foreign key constraint that references another table.
B. To define the data type of a column.
C. To retrieve data from a table.
D. To define primary keys for a table.
Answer: A
Which of the following is the purpose of the “IN” operator in SQL?
It returns the number of rows in the result set.
B. It checks if a value is within a specified list of values.
C. It joins tables based on a common column.
D. It limits the number of rows returned.
Answer: B
What is the correct way to find the highest salary in a “employees” table using SQL?
SELECT MAX(salary) FROM employees;
B. SELECT MIN(salary) FROM employees;
C. SELECT salary FROM employees WHERE salary = MAX(salary);
D. SELECT salary FROM employees ORDER BY salary DESC LIMIT 1;
Answer: A
Which SQL function would you use to calculate the average value of a numeric column?
COUNT()
B. AVG()
C. SUM()
D. MAX()
Answer: B
In SQL, which of the following is used to check for pattern matches in string data?
LIKE
B. EQUAL
C. BETWEEN
D. IN
Answer: A
What is an “index” in a relational database?
A backup of the database.
B. A way to optimize the database by storing copies of frequently accessed data.
C. A way to group data into distinct values.
D. A reference to a foreign key.
Answer: B
Which of the following is a disadvantage of using “denormalization” in a database?
It can lead to increased redundancy and storage requirements.
B. It reduces query performance by making joins slower.
C. It requires more complex queries to be written.
D. It introduces data integrity issues.
Answer: A
What is the purpose of the “DISTINCT” keyword in SQL?
It retrieves only distinct (unique) values from a column.
B. It joins two tables together.
C. It filters records based on a condition.
D. It limits the number of rows returned.
Answer: A
What is a “subquery” in SQL?
A query that is nested within another query.
B. A function that sums values in a column.
C. A query that deletes data from a table.
D. A query that updates data in a table.
Answer: A
Reviews
There are no reviews yet.