Microsoft SQL Server Database Quiz Questions

Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:Logical Operators
Current Quiz Count:45
Progress
0%
Q1
True / False

The AND operator returns true only if both conditions are true.

Q2
True / False

The OR operator returns true if at least one condition is true.

Q3
True / False

The NOT operator reverses the result of a condition.

Q4
True / False

The AND operator has higher precedence than the OR operator.

Q5
True / False

Logical operators can be used in the WHERE clause of a SELECT statement.

Q6
True / False

The AND operator can be used to combine multiple conditions in an UPDATE statement.

Q7
True / False

The OR operator can be used to combine multiple conditions in a DELETE statement.

Q8
True / False

The NOT operator can be used to exclude records in a SELECT statement.

Q9
True / False

The AND operator is evaluated before the OR operator in a SQL query.

Q10
True / False

Logical operators cannot be used with the BETWEEN operator.

Q11
True / False

The OR operator has lower precedence than the AND operator.

Q12
True / False

The NOT operator can be used to reverse the result of an IS NULL condition.

Q13
True / False

The AND and OR operators cannot be used together in a single WHERE clause.

Q14
True / False

The OR operator can be used to combine conditions in a HAVING clause.

Q15
True / False

The AND operator can be used to check multiple conditions in a CASE statement.

Q16
Single Choice

Which logical operator is used to combine conditions where all conditions must be true?

Q17
Single Choice

Which logical operator can be used to reverse the result of a condition?

Q18
Single Choice

Which logical operator has the highest precedence?

Q19
Single Choice

Which operator would you use to combine conditions in a WHERE clause where at least one condition must be true?

Q20
Single Choice

Which operator is used to negate a condition?

Q21
Single Choice

In which clause can the AND operator be used?

SQL Code
SELECT * FROM Customers
WHERE Country = 'USA' AND City = 'New York';
Q22
Single Choice

In which clause can the OR operator be used?

SQL Code
SELECT * FROM Customers
WHERE Country = 'USA' OR Country = 'Canada';
Q23
Single Choice

In which clause can the NOT operator be used?

SQL Code
SELECT * FROM Customers
WHERE NOT Country = 'USA';
Q24
Single Choice

Which logical operator is evaluated first in a SQL query?

Q25
Single Choice

Which logical operator is evaluated last in a SQL query?

Q26
Single Choice

Which operator can be used to combine multiple conditions in a WHERE clause?

SQL Code
SELECT * FROM Employees
WHERE Age > 30 AND Department = 'Sales';
Q27
Single Choice

Which operator can be used to combine conditions that involve NULL values?

SQL Code
SELECT * FROM Employees
WHERE Age IS NULL OR Age > 30;
Q28
Single Choice

Which operator can be used to exclude certain records based on a condition?

SQL Code
SELECT * FROM Employees
WHERE NOT Department = 'Sales';
Q29
Single Choice

Which operator can be used to combine multiple conditions in a HAVING clause?

SQL Code
SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 10 AND AVG(Salary) > 50000;
Q30
Single Choice

Which operator can be used to combine conditions in a CASE statement?

SQL Code
SELECT Name,
CASE
 WHEN Age > 30 AND Department = 'Sales' THEN 'Senior Sales'
 ELSE 'Other'
END
FROM Employees;
Q31
Multiple Choice

Which operators can be used to combine conditions in a WHERE clause?

SQL Code
SELECT * FROM Employees
WHERE Age > 30 AND Department = 'Sales';
SELECT * FROM Customers
WHERE Country = 'USA' OR Country = 'Canada';
Q32
Multiple Choice

Which operators can be used to negate a condition?

SQL Code
SELECT * FROM Employees
WHERE NOT Department = 'Sales';
SELECT * FROM Customers
WHERE NOT Country = 'USA';
Q33
Multiple Choice

Which operators can be used to combine conditions involving NULL values?

SQL Code
SELECT * FROM Employees
WHERE Age IS NULL OR Age > 30;
SELECT * FROM Customers
WHERE Country IS NULL AND City IS NOT NULL;
Q34
Multiple Choice

Which operators can be used to combine multiple conditions in a HAVING clause?

SQL Code
SELECT Department, COUNT(*)
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 10 AND AVG(Salary) > 50000;
SELECT Department, SUM(Salary)
FROM Employees
GROUP BY Department
HAVING SUM(Salary) > 100000 OR COUNT(*) > 10;
Q35
Multiple Choice

Which operators can be used to combine conditions in a CASE statement?

SQL Code
SELECT Name,
CASE
 WHEN Age > 30 AND Department = 'Sales' THEN 'Senior Sales'
 ELSE 'Other'
END
FROM Employees;
SELECT Name,
CASE
 WHEN Country = 'USA' OR Country = 'Canada' THEN 'North America'
 ELSE 'Other'
END
FROM Customers;
Q36
Multiple Choice

Which operators can be used to combine conditions in an UPDATE statement?

SQL Code
UPDATE Employees
SET Salary = Salary + 1000
WHERE Age > 30 AND Department = 'Sales';
UPDATE Customers
SET Discount = 0.1
WHERE Country = 'USA' OR Country = 'Canada';
Q37
Multiple Choice

Which operators can be used to combine conditions in a DELETE statement?

SQL Code
DELETE FROM Employees
WHERE Age > 30 AND Department = 'Sales';
DELETE FROM Customers
WHERE Country = 'USA' OR Country = 'Canada';
Q38
Multiple Choice

Which operators can be used to combine conditions in a SELECT statement?

SQL Code
SELECT * FROM Employees
WHERE Age > 30 AND Department = 'Sales';
SELECT * FROM Customers
WHERE Country = 'USA' OR Country = 'Canada';
Q39
Multiple Choice

Which operators can be used to exclude certain records in a WHERE clause?

SQL Code
SELECT * FROM Employees
WHERE NOT Department = 'Sales';
SELECT * FROM Customers
WHERE NOT Country = 'USA';
Q40
Multiple Choice

Which operators can be used to combine conditions in a JOIN clause?

SQL Code
SELECT Employees.Name, Departments.Name
FROM Employees
JOIN Departments ON Employees.DepartmentId = Departments.Id
WHERE Employees.Age > 30 AND Departments.Budget > 100000;
SELECT Employees.Name, Departments.Name
FROM Employees
JOIN Departments ON Employees.DepartmentId = Departments.Id
WHERE Employees.Age > 30 OR Departments.Budget > 100000;
Q41
Multiple Choice

Which operators can be used to combine conditions in a subquery?

SQL Code
SELECT * FROM Employees
WHERE Age > 30 AND Department IN (SELECT Department FROM Departments WHERE Budget > 100000);
SELECT * FROM Customers
WHERE Country = 'USA' OR Country IN (SELECT Country FROM Countries WHERE Continent = 'North America');
Q42
Multiple Choice

Which operators can be used to combine conditions in an INSERT statement?

SQL Code
INSERT INTO Employees (Name, Age, Department)
SELECT 'John', 35, 'Sales'
WHERE EXISTS (SELECT 1 FROM Departments WHERE Name = 'Sales' AND Budget > 100000);
INSERT INTO Customers (Name, Country)
SELECT 'Alice', 'USA'
WHERE NOT EXISTS (SELECT 1 FROM Customers WHERE Name = 'Alice' AND Country = 'USA');
Q43
Multiple Choice

Which operators can be used to combine conditions in an ALTER statement?

SQL Code
ALTER TABLE Employees
ADD CONSTRAINT chk_Age CHECK (Age > 30 AND Age < 65);
ALTER TABLE Customers
ADD CONSTRAINT chk_Country CHECK (Country = 'USA' OR Country = 'Canada');
Q44
Multiple Choice

Which operators can be used to combine conditions in a MERGE statement?

SQL Code
MERGE INTO Employees AS target
USING (SELECT * FROM NewEmployees) AS source
ON target.Id = source.Id
WHEN MATCHED AND source.Age > 30 THEN UPDATE SET target.Age = source.Age
WHEN NOT MATCHED BY TARGET AND source.Department = 'Sales' THEN INSERT (Name, Age, Department) VALUES (source.Name, source.Age, source.Department);
MERGE INTO Customers AS target
USING (SELECT * FROM NewCustomers) AS source
ON target.Id = source.Id
WHEN MATCHED OR source.Country = 'USA' THEN UPDATE SET target.Country = source.Country
WHEN NOT MATCHED BY TARGET AND source.Region = 'North America' THEN INSERT (Name, Country, Region) VALUES (source.Name, source.Country, source.Region);
Q45
Multiple Choice

Which operators can be used to combine conditions in a TRUNCATE statement?

SQL Code
TRUNCATE TABLE Employees
WHERE EXISTS (SELECT 1 FROM Departments WHERE Name = 'Sales' AND Budget > 100000);
TRUNCATE TABLE Customers
WHERE NOT EXISTS (SELECT 1 FROM Orders WHERE CustomerId = Customers.Id AND OrderDate > '2023-01-01');