MySQL Integration - database connection, table creation with constraints, CRUD operations, joins, subqueries, querying MySQL with PHP - Question Bank
1. Which SQL command is used to drop (delete) a table from a database?
2. What is an index in MySQL, and why is it used?
3. Which of the following represents a valid way to define a `CHECK` constraint in MySQL?
4. What is the primary benefit of using the `mysqli` extension over the older `mysql_*` functions in PHP?
5. Which SQL statement is used to add a new column named 'email' to an existing table 'users'?
6. What does the `LIMIT` clause in MySQL do?
7. To sort results in descending order using `ORDER BY`, what keyword is appended?
8. What is the purpose of the `ORDER BY` clause in SQL?
9. Which PHP function is used to get the number of rows in a MySQL result set?
10. What is the difference between `WHERE` and `HAVING` clauses in SQL?
11. The `HAVING` clause is used to filter groups created by the `GROUP BY` clause. What kind of condition can `HAVING` filter on?
12. Which SQL clause is used to group rows that have the same values in specified columns into summary rows?
13. What is the main advantage of using `mysqli_real_escape_string()` in PHP before inserting user input into SQL queries?
14. Consider the SQL query: `SELECT COUNT(*) FROM users WHERE country = 'USA';`. What does `COUNT(*)` represent?
15. What does `mysqli_fetch_all()` do?
16. Which PHP function is used to fetch the next row from a result set as a numeric array?
17. What is the SQL statement to create a table named `products` with columns `id` (INT, PRIMARY KEY, AUTO_INCREMENT), `name` (VARCHAR(255), NOT NULL), and `price` (DECIMAL(10, 2))?
18. Which PHP function is used to get the last inserted ID from an AUTO_INCREMENT column after an INSERT query?
19. When querying MySQL with PHP using `mysqli_query()`, what is returned if the query is a data retrieval statement (like SELECT)?
20. What is the purpose of the `ON DELETE CASCADE` option for a foreign key?
21. Which of the following best describes the `FOREIGN KEY` constraint?
22. What is the recommended method for handling errors when performing MySQL operations in PHP?
23. In PHP, what is the correct way to close a MySQLi connection?
24. Which operator is commonly used to compare the result of a subquery with a value or column in the outer query?
25. What is the purpose of the `WHERE` clause when used with a subquery?
26. Which clause can a subquery typically be used within?
27. What is a subquery in SQL?
28. Consider two tables, `Customers` (CustomerID, Name) and `Orders` (OrderID, CustomerID, OrderDate). A `LEFT JOIN` between `Customers` and `Orders` on `CustomerID` will show:
29. Which JOIN type returns all rows from both tables, and fills in NULLs where there is no match on either side?
30. An `INNER JOIN` returns only rows where the join condition is met in both tables. What kind of result does it produce?
31. Which type of JOIN returns all rows from the left table and the matched rows from the right table, or NULLs if there is no match?
32. What is a `JOIN` operation in SQL used for?
33. What does `mysqli_bind_param()` do in the context of prepared statements?
34. Which PHP function is used to prepare a statement for execution in MySQLi?
35. What is the primary purpose of using prepared statements in PHP with MySQL?
36. Which PHP function is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE query?
37. What does `mysqli_fetch_assoc()` do in PHP when processing query results?
38. In PHP, what is the typical function used to execute a SQL query against a MySQL database after establishing a connection?
39. Which SQL statement is used to remove records from a MySQL table?
40. To modify existing records in a MySQL table, which SQL statement is used?
41. Which SQL statement corresponds to the 'Read' operation in CRUD?
42. Which SQL statement is used for the 'Create' operation in CRUD?
43. What does 'CRUD' stand for in the context of database operations?
44. In SQL, what does the `AUTO_INCREMENT` attribute typically do for a column?
45. What is the purpose of the `UNIQUE` constraint in a MySQL table?
46. Which constraint is used to ensure that a column cannot have a NULL value?
47. When creating a table in MySQL, what does the `PRIMARY KEY` constraint signify?
48. What does the `mysqli_error()` function return if a connection attempt fails?
49. Which of the following is a common parameter for mysqli_connect() to specify the database server?
50. What is the primary purpose of the mysqli_connect() function in PHP for MySQL integration?