Basic Data Retrieval
What SQL statement is used to retrieve all columns from a table called 'users'?
- SELECT * FROM users;
- GET * FROM users;
- FETCH ALL users;
- RETRIEVE users ALL;
- SELECT ALL FROM users;
Filtering Data
Which clause would you use in an SQL query to filter results based on a specific condition?
- WHERE
- FILTER
- HAVING
- WHICH
- CONDITION
Database Connection
Which method is commonly used in PHP to securely connect to a MySQL database and prevent SQL Injection?
- Using prepared statements with PDO
- Building queries with string concatenation
- Using eval() to construct queries
- Directly inserting variables into SQL strings
- Connecting without authentication
Primary Keys
What is the primary key used for in a MySQL table?
- To uniquely identify each row
- To encrypt table data
- To store index position
- To define a foreign table
- To increase query speed only
UPDATE Statement Syntax
Which of the following is the correct syntax to update the 'email' column to 'user@example.com' for the user with id 5 in a 'users' table?
- UPDATE users SET email = 'user@example.com' WHERE id = 5;
- MODIFY users email = 'user@example.com' WHEN id = 5;
- CHANGE users TO email = 'user@example.com' IF id = 5;
- UPDATE users ON email = 'user@example.com' WHERE id = 5;
- UPDATE users SET email: 'user@example.com' WHERE id == 5;
SQL Injection Prevention
How can you best prevent SQL Injection attacks in your database queries?
- By using parameterized queries
- By hashing all user data
- By removing all user input
- By disabling database logging
- By setting a strong password
Aggregate Functions
Which SQL function returns the total number of rows in a table, including those with NULL values?
- COUNT(*)
- SUM(*)
- TOTAL()
- ADDALL(*)
- COUNT_ROWS()
Sorting Results
What keyword would you use to sort the results of a query in ascending order based on the 'created_at' column?
- ORDER BY created_at ASC
- SORT BASED created_at UP
- SORT BY created_at ASCENDING
- ORDER ON created_at ALPHABET
- ARRANGE created_at ASC
NULL Value Checking
How do you check if the column 'email' is NULL in a WHERE clause?
- WHERE email IS NULL
- WHERE email = NULL
- WHERE email EQUALS NULL
- WHERE email ISNOT SET
- WHERE NULL email
Limiting Results
Which clause is used in a SELECT statement to limit the number of rows returned?
- LIMIT
- ROWLIMIT
- FETCH
- TOP
- MAXROWS