Summary

This document contains practice questions related to SQL (Structured Query Language) and relational databases. The questions cover various SQL concepts such as SELECT statements, JOIN operations, data types, functions, and database management tasks.

Full Transcript

1. Which of the following is a Relational Database Management System (RDBMS)? a) MySQL b) Oracle c) Microsoft Access d) All of the above 2. What is the most common SQL statement used to retrieve data from a database? a) CREATE b) INSERT c) SELECT d) UPDATE 3. What data type in SQL is best suited f...

1. Which of the following is a Relational Database Management System (RDBMS)? a) MySQL b) Oracle c) Microsoft Access d) All of the above 2. What is the most common SQL statement used to retrieve data from a database? a) CREATE b) INSERT c) SELECT d) UPDATE 3. What data type in SQL is best suited for storing dates? a) VARCHAR b) INT c) DATE d) FLOAT 4. Which clause is used to specify a condition in a SELECT statement? a) FROM b) WHERE c) ORDER BY d) GROUP BY 5. What does the JOIN operation do in SQL? a) Creates a new table b) Combines data from two or more tables c) Deletes data from a table d) Updates data in a table 6. Which SQL keyword is used to combine the results of two or more SELECT statements? a) JOIN b) UNION c) Merge d) Combine 7. Which SQL command is used to permanently delete a table? a) ALTER TABLE b) DROP TABLE c) DELETE d) UPDATE 8. What function can be used to count the number of rows in a table? a) SUM b) COUNT c) AVG d) MAX 9. The WHERE clause filters data based on a specific condition. What operator is used for comparisons? a) = b) + c) * d) , 10. What does the DISTINCT keyword do in a SELECT statement? a) Sorts the results b) Returns only unique values c) Limits the number of rows returned d) Groups the results 11. What is the difference between an INNER JOIN and an OUTER JOIN? a) INNER JOIN returns all matching rows, while OUTER JOIN returns all rows from one table. b) There is no difference. c) INNER JOIN is used for dates, while OUTER JOIN is used for text data. d) OUTER JOIN is faster than INNER JOIN. 12. What is the purpose of a primary key in a table? a) To define the data type of a column b) To uniquely identify each row in a table c) To define a relationship between tables d) To store descriptive information about the table 13. What does the ORDER BY clause do in a SELECT statement? a) Filters data based on a condition b) Sorts the results c) Limits the number of rows returned d) Groups the results 14. What is the difference between UPDATE and DELETE statements? a) UPDATE modifies existing data, while DELETE removes data entirely b) There is no difference. c) UPDATE is used for numeric data, while DELETE is used for text data. d) DELETE is faster than UPDATE. 15. What is a subquery in SQL? a) A query nested within another b) A special type of join c) A function used for string manipulation d) A way to define user permissions 16. What is the syntax for creating a new table in SQL? a) CREATE TABLE table_name (column1 datatype, column2 datatype,...); b) INSERT INTO table_name (column1, column2,...) VALUES (...); c) SELECT * FROM table_name; d) DROP TABLE table_name; 17. Which of the following is a single-row function? a) Concat b) lower c) upper d) All of the above 18. What does the LIKE operator do in a WHERE clause? a) Performs an exact comparison b) Performs a pattern matching search c) Sorts the results d) Groups the results 19. What is the function of the GROUP BY clause? a) Filters data based on a condition b) Sorts the results c) Groups data based on one or more columns d) Limits the number of rows returned 20. What is an alias in SQL? a) A reserved keyword b) A temporary name assigned to a table or column c) A data type d) A user-defined function 21. What is the purpose of a foreign key in a database? a) To define the data type of a column b) To create a relationship between tables, enforcing referential integrity c) To uniquely identify each row in a table d) To store descriptive information about the table 22. What does the HAVING clause do in a SELECT statement used with GROUP BY? a) Filters groups based on a condition applied to aggregate functions b) Filters individual rows based on a condition c) Sorts the grouped results d) Limits the number of groups returned 23. What is the difference between UNION and UNION ALL operators in SQL? a) UNION removes duplicates, while UNION ALL keeps all rows b) There is no difference. c) UNION is used for numeric data, while UNION ALL is used for text data. d) UNION ALL is faster than UNION. 24. The symbol || represent for which of the following? a) concat operator b) concatenation operator c) alias d) none of the above 25. Which one is faster in terms of performance: UNION or UNION ALL? a) UNION b) UNION ALL c) Both have same performance d) None 26. What is the difference between schema and table in a database? a) Schema is a blueprint for the database structure, defining tables and their relationships. Tables store the actual data. b) There is no difference. c) Schema is used for numeric data, while tables are used for text data. d) Tables are faster to access than schemas. 27. select substr('helloworld', -1, instr('helloworld', 'l', 3, 2)) from dual; a) hell b) d c) orld d) error 28. Which of the following query finds the total rating of the sailors who have reserved boat 103? a) SELECT SUM(s.rating) FROM sailors s, reserves r AND r.bid = 103; b) SELECT s.rating FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103; c) SELECT COUNT(s.rating) FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103; d) SELECT SUM(s.rating) FROM sailors s, reserves r WHERE s.sid = r.sid AND r.bid = 103; 29. Select the correct statement.? a) DDL consist of 4 commands b) DCL consist of 2 commands c) TCL consist of 5 commands d) DML consist of 3 commands 30. Which of the following is TRUE about TCL? a. Transactions can be saved to the database and rolled back with the help of TCL commands in SQL. b. There will be certain privileges that each user has; consequently, the data can be accessed by them using TCL. c. Our data is stored in a table that is described by the schema, thus TCL commands deal with the schema. d. SQL TCL commands can be used to perform any kind of retrieval or manipulation of the data present in SQL tables 32. What does the COMMIT statement do in a transaction? a) Starts a new transaction b) Rolls back changes made within a transaction c) Saves the changes made within a transaction d) Grants access permissions to a user 33. What is the ROLLBACK statement used for in a transaction? a) Saves the changes made within a transaction b) Continues a transaction c) Reverts all changes made within a transaction d) Defines a user-defined function 34. What is the purpose of data types in SQL? a) To define the access level of users b) To specify the format and range of allowed values for a column c) To create relationships between tables d) To manage database storage 35. Table Employee has 10 records. It has a non-NULL SALARY column which is also UNIQUE. What will be the output of the given SQL Statement: SELECT COUNT(*) FROM employee WHERE SALARY > ANY (SELECT SALARY FROM EMPLOYEE); a) 10 b) 1 c) 9 d) 0 36. The SQL Statement: SELECT SUBSTR ('abcabcabc', INSTR ('123321123', '3', 3, 2), 2) FROM DUAL; a) ab b) bc c) ca d) null 37. What is the difference between an inner join and a self-join? a) An inner join combines data from two tables, while a self-join joins a table to itself. b) There is no difference. c) Inner join is used for numeric data, while self-join is used for text data. d) Self-join is faster than inner join. 38. The SQL statement: SELECT ROUND (55.926, -1) FROM DUAL; a) is illegal b) prints 56 c) print 50 d) print 60 39. What is the difference between logical operators (AND, OR, NOT) and comparison operators (=, )? a) Logical operators combine conditions, while comparison operators evaluate expressions. b) There is no difference. c) Logical operators are used for numeric data, while comparison operators are used for text data. d) Comparison operators are faster than logical operators. 40. What is the purpose of functions in SQL? a) To define the structure of a table b) To perform calculations or manipulations on data c) To create relationships between tables d) To manage database users 41. What is the difference between aggregate functions (SUM, AVG, COUNT) and scalar functions (UPPER, LOWER, LENGTH)? a) Aggregate functions operate on groups of data, returning a single value, while scalar functions operate on individual values. b) There is no difference. c) Aggregate functions are used for numeric data, while scalar functions are used for text data. d) Scalar functions are faster than aggregate functions. 42. Select * from customer join order on customer.customerid = order.customerid; This query is equivalent to? a) Select * from customer natural join order; b) Select * from customer left join order on customer.customerid = order.customerid; c) Select * from customer right join order on customer.customerid = order.customerid; d) Select * from customer full join order on customer.customerid = order.customerid; 43. How to select all data from student table starting the name from letter 'r'? a) SELECT * FROM student WHERE name LIKE 'r%'; b) SELECT * FROM student WHERE name LIKE '%r%'; c) SELECT * FROM student WHERE name LIKE '%r'; d) SELECT * FROM student WHERE name LIKE '_r%'; 44. Which of the following SQL statements is used to retrieve data from a table named "customers" and display all columns? a) CREATE TABLE customers (id INT, name VARCHAR (255)); b) INSERT INTO customers (id, name) VALUES (1, "John Doe"); c) SELECT * FROM customers; d) UPDATE customers SET name = "Jane Doe" WHERE id = 1; 45. How can you filter the results in the "customers" table to only show customers with an ID greater than 10? a) SELECT * FROM customers; b) SELECT * FROM customers WHERE id > 10; c) DELETE FROM customers WHERE id > 10; d) GROUP BY id FROM customers; 46. What SQL statement would you use to display the number of customers in the "customers" table? a) SELECT COUNT (*) FROM customers; b) SELECT id FROM customers; c) UPDATE customers SET name = UPPER (name); d) ORDER BY id ASC FROM customers; 47. How can you retrieve the names of all customers from the "customers" table, sorted alphabetically (ascending order) by their names? a) SELECT * FROM customers; b) SELECT name FROM customers ORDER BY name; c) SELECT name FROM customers WHERE name LIKE "%Doe%"; d) GROUP BY name FROM customers;