OA Exams
Which SQL command is used to remove a database entirely, including all its tables?
a) DROP DATABASEb) DELETE DATABASEc) TRUNCATE DATABASEd) REMOVE DATABASE
Correct Answer: a) DROP DATABASE
Explanation: The DROP DATABASE command is used to remove a database and all its tables from the database management system.
Which SQL statement is used to modify the structure of an existing table?
a) CREATE TABLEb) ALTER TABLEc) DROP TABLEd) UPDATE TABLE
Correct Answer: b) ALTER TABLE
Explanation: The ALTER TABLE statement is used to change the structure of an existing table, such as adding or dropping columns.
In SQL, which command is used to create a new table?
a) CREATE TABLEb) INSERT TABLEc) ADD TABLEd) NEW TABLE
Correct Answer: a) CREATE TABLE
Explanation: The CREATE TABLE command is used to define a new table and its columns within the database.
Which SQL clause is used to filter records after they have been grouped?
a) WHEREb) HAVINGc) GROUP BYd) LIMIT
Correct Answer: b) HAVING
Explanation: The HAVING clause is used to filter groups of records after the aggregation has been performed with the GROUP BY clause.
Which SQL command is used to change data in an existing row?
a) INSERTb) UPDATEc) DELETEd) MODIFY
Correct Answer: b) UPDATE
Explanation: The UPDATE command is used to modify existing records in a table based on specified conditions.
What is the purpose of a primary key in a database?
a) To store duplicate valuesb) To uniquely identify each row in a tablec) To reference another tabled) To enforce referential integrity
Correct Answer: b) To uniquely identify each row in a table
Explanation: A primary key uniquely identifies each row in a table, ensuring that no two rows have the same value in the primary key column(s).
Which SQL function is used to retrieve the minimum value from a column?
a) MIN()b) MAX()c) AVG()d) SUM()
Correct Answer: a) MIN()
Explanation: The MIN() function returns the smallest value from a specified column in SQL.
Which type of join returns only the rows that have matching values in both tables?
a) INNER JOINb) LEFT JOINc) RIGHT JOINd) FULL JOIN
Correct Answer: a) INNER JOIN
Explanation: An INNER JOIN returns only the rows that have matching values in both tables involved in the join.
Which SQL statement is used to remove all rows from a table but keep the structure intact?
a) DELETEb) TRUNCATEc) DROP TABLEd) CLEAR
Correct Answer: b) TRUNCATE
Explanation: The TRUNCATE command removes all rows from a table without affecting the table's structure.
What does the SQL keyword UNIQUE ensure for a column?
a) Values can be duplicatedb) Values must be unique across the columnc) Values can be NULLd) Values must be the same as another column
Correct Answer: b) Values must be unique across the column
Explanation: The UNIQUE constraint ensures that all values in a specified column are distinct from each other.
Which SQL operator is used to compare a value against a list of values?
a) LIKEb) INc) BETWEENd) EXISTS
Correct Answer: b) IN
Explanation: The IN operator is used to determine if a value matches any value in a specified list.
Which clause is used to specify the column names when creating a table?
a) SETb) COLUMNc) CREATEd) AS
Correct Answer: c) CREATE
Explanation: The CREATE command is followed by the specification of column names and their data types when creating a new table.
In SQL, which function returns the current date and time?
a) CURDATE()b) NOW()c) GETDATE()d) DATE()
Correct Answer: b) NOW()
Explanation: The NOW() function retrieves the current date and time from the system clock.
Which SQL statement is used to create a view?
a) CREATE VIEWb) NEW VIEWc) MAKE VIEWd) DEFINE VIEW
Correct Answer: a) CREATE VIEW
Explanation: The CREATE VIEW statement is used to define a new view based on a SELECT query, allowing for simplified data retrieval.
Which SQL clause is used to sort the result set in ascending order?
a) ORDER BYb) GROUP BYc) SORT BYd) LIMIT
Correct Answer: a) ORDER BY
Explanation: The ORDER BY clause sorts the result set based on one or more columns in ascending order by default.
What is the main function of a foreign key in a database?
a) To enforce data integrityb) To store large objectsc) To retrieve data quicklyd) To ensure unique values
Correct Answer: a) To enforce data integrity
Explanation: A foreign key establishes a link between two tables, ensuring that the data remains consistent and valid.
Which SQL function is used to calculate the average of a set of values?
a) AVG()b) SUM()c) COUNT()d) MEDIAN()
Correct Answer: a) AVG()
Explanation: The AVG() function computes the average value of a specified column in SQL.
Which SQL clause filters records before any grouping is applied?
a) WHEREb) HAVINGc) GROUP BYd) ORDER BY
Correct Answer: a) WHERE
Explanation: The WHERE clause is applied to filter rows before they are grouped in a GROUP BY operation.
Which SQL command is used to define a new user in a database?
a) CREATE USERb) ADD USERc) INSERT USERd) DEFINE USER
Correct Answer: a) CREATE USER
Explanation: The CREATE USER command is used to establish a new user account in the database management system.
Which SQL statement is used to update values in a table?
a) MODIFYb) CHANGEc) UPDATEd) ALTER
Correct Answer: c) UPDATE
Explanation: The UPDATE statement is used to modify existing records in a table.