Consider a table Employees without a primary key. What will be the result of this query?
SELECT EmployeeID, COUNT(*) FROM Employees GROUP BY EmployeeID;
Assuming EmployeeID is not unique in the table.
CREATE TABLE Employees (EmployeeID INT, Name VARCHAR(100)); INSERT INTO Employees VALUES (1, 'Alice'), (1, 'Alice'), (2, 'Bob'); SELECT EmployeeID, COUNT(*) FROM Employees GROUP BY EmployeeID;
Think about how GROUP BY works with duplicate rows.
Without a primary key, duplicate EmployeeID values can exist. GROUP BY counts all rows per EmployeeID.
Which of the following best explains why normalization is important in table design?
Think about what happens when the same data is stored in many places.
Normalization organizes data to reduce repetition and avoid inconsistencies when updating data.
Which SQL statement correctly adds a foreign key constraint to the Orders table referencing Customers?
ALTER TABLE Orders ADD CONSTRAINT fk_customer FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID);
Check the syntax for adding constraints with parentheses.
The correct syntax requires parentheses around the column name and the REFERENCES clause.
You have a large Sales table with columns SaleID, ProductID, and SaleDate. Which index will speed up this query?
SELECT * FROM Sales WHERE ProductID = 101 AND SaleDate = '2024-01-01';
Think about which columns appear together in the WHERE clause and their order.
A composite index on (ProductID, SaleDate) matches the query filter and speeds up lookups.
A table Inventory stores product quantities but allows duplicate ProductID rows. What problem can this cause?
Think about what happens when the same product appears multiple times with quantities.
Duplicates cause sums or counts to be wrong because the same product is counted multiple times.