Basic SELECT Syntax
Which SQL statement correctly retrieves all columns from a table named Employees?
- SELECT * FROM Employees;
- SELLECT ALL FROM Employees;
- SELECT * IN Employees;
- GET * FROM Employees;
- SELECT ALL Employees;
Inserting Data Correctly
Which statement correctly inserts a new row into the Customers table with values for Name and Email?
- INSERT INTO Customers (Name, Email) VALUES ('John Doe', 'john@example.com');
- INSERT Customers Name, Email VALUES ('John Doe', 'john@example.com');
- INSERT INTO Customers VALUES (Name='John Doe', Email='john@example.com');
- INERT INTO Customers (Name, Email) VALUES ('John Doe, 'john@example.com');
- INSERT TO Customers (Name Email) VALUES 'John Doe', 'john@example.com';
Updating Existing Data
If you want to change the Price to 19.99 for the product with ID 3 in the Products table, which SQL command should you use?
- UPDATE Products SET Price = 19.99 WHERE ID = 3;
- CHANGE Products SET Price = 19.99 WHERE ID is 3;
- UPDATE Products Price = 19.99 WHEN ID = 3;
- MODIFY Products (Price = 19.99) WHERE ID = 3;
- UPDATE Product SET Price to 19.99 where ID = 3;
Efficient Data Deletion
What is the correct SQL command to delete all records from the Orders table where the Status is 'Canceled'?
- DELETE FROM Orders WHERE Status = 'Canceled';
- REMOVE FROM Orders WHERE Status = 'Canceled';
- DELETE * FROM Orders WHERE Status = 'Canceled';
- DELETE Orders WHERE Status = 'Canceled';
- REMOVE Orders WHERE Status EQUALS 'Canceled';
Limiting Query Results
Which SQL statement fetches only the first 10 rows from a table named Sales?
- SELECT * FROM Sales LIMIT 10;
- SELECT ALL FROM Sales TOP 10;
- SELECT FIRST 10 * FROM Sales;
- SELECT TOP 10 FROM Sales;
- SELECT * FROM Sales ROWNUM = 10;
Filtering Query Data
What is the correct SQL way to select employees whose last name is 'Smith'?
- SELECT * FROM Employees WHERE LastName = 'Smith';
- SELECT * FROM Employees IF LastName = 'Smith';
- SELECT * Employees WHERE LastName == 'Smith';
- SELECT FROM Employees WHERE LastName = Smith;
- SELECT Employees WHERE LastName EQUAL 'Smith';
Preventing SQL Injection
Which strategy is best for preventing SQL injection when using SQL queries in application code?
- Use parameterized queries or prepared statements.
- Concatenate user input directly into SQL queries.
- Use SELECT * to reduce complexity.
- Delete unnecessary constraints from all tables.
- Only use the LIMIT clause in queries.
Aggregating Data
How can you count the number of products in the Products table using SQL?
- SELECT COUNT(*) FROM Products;
- COUNT * FROM Products;
- SELECT PRODUCT_COUNT() FROM Products;
- SELECT COUNT FROM Products;
- SELECT * FROM Products COUNT;
Optimizing Query Performance
Which optimization technique improves query performance, especially on large tables?
- Create indexes on frequently filtered columns.
- Use SELECT * in all queries.
- Avoid using WHERE clauses.
- Always retrieve all rows with no limits.
- Drop all constraints from the table.
Updating Multiple Records
You need to increase the salary by 5% for all employees in the 'Sales' department. Which SQL UPDATE is correct?
- UPDATE Employees SET Salary = Salary * 1.05 WHERE Department = 'Sales';
- UPDATE Employees Salary = Salary + 5% WHERE Department = 'Sales';
- UPDATE Employees WHERE Department = 'Sales' INCREASE Salary BY 5%;
- SET Salary = Salary * 1.05 FROM Employees WHERE Department = 'Sales';
- UPDATE Set Salary = Salary + 5 percent WHERE Employees.Department = 'Sales';