0% found this document useful (0 votes)
9 views8 pages

SQL Iti Level

The document contains 30 multiple-choice questions (MCQs) related to SQL concepts, including basic commands like SELECT, INSERT, UPDATE, and DELETE, as well as advanced topics such as JOINs, aggregate functions, and SQL injection prevention. Each question is followed by four answer options, with the correct answer indicated. The content serves as a study guide for individuals preparing for SQL-related assessments or exams.

Uploaded by

Antonuose Gerges
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

SQL Iti Level

The document contains 30 multiple-choice questions (MCQs) related to SQL concepts, including basic commands like SELECT, INSERT, UPDATE, and DELETE, as well as advanced topics such as JOINs, aggregate functions, and SQL injection prevention. Each question is followed by four answer options, with the correct answer indicated. The content serves as a study guide for individuals preparing for SQL-related assessments or exams.

Uploaded by

Antonuose Gerges
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL ITI Level – 30 MCQs

1. Basic SELECT

Which SQL statement is used to select all columns from the table employees?
a) SELECT ALL FROM employees;
b) SELECT * FROM employees;
c) SELECT employees;
d) SELECT # FROM employees;

Answer: b) SELECT * FROM employees;

2. WHERE clause

Which query selects employees with a salary greater than 5000?


a) SELECT * FROM employees WHERE salary = 5000;
b) SELECT * FROM employees WHERE salary > 5000;
c) SELECT * FROM employees IF salary > 5000;
d) SELECT * FROM employees HAVING salary > 5000;

Answer: b) SELECT * FROM employees WHERE salary > 5000;

3. ORDER BY

How do you sort employees by name in ascending order?


a) SELECT * FROM employees ORDER BY name ASC;
b) SELECT * FROM employees SORT BY name;
c) SELECT * FROM employees ORDER name ASC;
d) SELECT * FROM employees GROUP BY name ASC;

Answer: a) SELECT * FROM employees ORDER BY name ASC;

4. DISTINCT

What does the DISTINCT keyword do?


a) Returns all rows including duplicates
b) Returns only unique rows
c) Deletes duplicate rows
d) Groups rows
Answer: b) Returns only unique rows

5. Aggregate Functions

Which function calculates the average salary?


a) SUM(salary)
b) AVG(salary)
c) MAX(salary)
d) COUNT(salary)

Answer: b) AVG(salary)

6. GROUP BY

To find the number of employees in each department:


a) SELECT department, COUNT() FROM employees;
b) SELECT department, COUNT() FROM employees GROUP BY department;
c) SELECT COUNT() FROM employees GROUP BY department;
d) SELECT department, COUNT() GROUP BY employees;

Answer: b) SELECT department, COUNT(*) FROM employees GROUP BY department;

7. HAVING

Which query finds departments with more than 10 employees?


a) SELECT department, COUNT() FROM employees WHERE COUNT() > 10;
b) SELECT department, COUNT() FROM employees HAVING COUNT() > 10 GROUP BY
department;
c) SELECT department, COUNT() FROM employees GROUP BY department HAVING
COUNT() > 10;
d) SELECT department, COUNT() FROM employees GROUP BY department WHERE
COUNT() > 10;

Answer: c) SELECT department, COUNT() FROM employees GROUP BY department


HAVING COUNT() > 10;

8. INSERT
Which is correct to add a new employee?
a) INSERT INTO employees VALUES (101, 'Ali', 3000);
b) ADD INTO employees VALUES (101, 'Ali', 3000);
c) INSERT employees VALUES (101, 'Ali', 3000);
d) CREATE INTO employees VALUES (101, 'Ali', 3000);

Answer: a) INSERT INTO employees VALUES (101, 'Ali', 3000);

9. UPDATE

How to increase all salaries by 10%?


a) UPDATE employees SET salary = salary * 1.1;
b) UPDATE employees ADD salary * 0.1;
c) MODIFY employees SET salary = salary + 10%;
d) UPDATE employees SET salary += 10%;

Answer: a) UPDATE employees SET salary = salary * 1.1;

10. DELETE

Delete all employees in department 5:


a) DELETE employees WHERE department = 5;
b) DELETE FROM employees WHERE department = 5;
c) REMOVE FROM employees WHERE department = 5;
d) DELETE * FROM employees WHERE department = 5;

Answer: b) DELETE FROM employees WHERE department = 5;

11. JOIN

Which query selects employees and their department names?


a) SELECT * FROM employees JOIN departments ON employees.dep_id = departments.id;
b) SELECT * FROM employees INNER JOIN departments;
c) SELECT * FROM employees CROSS JOIN departments;
d) SELECT * FROM employees FULL JOIN departments;

Answer: a) SELECT * FROM employees JOIN departments ON employees.dep_id =


departments.id;
12. LEFT JOIN

Returns all employees and department names (NULL if no department):


a) LEFT JOIN
b) RIGHT JOIN
c) INNER JOIN
d) CROSS JOIN

Answer: a) LEFT JOIN

13. Subquery

Select employees earning more than the average salary:


a) SELECT * FROM employees WHERE salary > SELECT AVG(salary) FROM employees;
b) SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
c) SELECT * FROM employees WHERE salary > AVG(salary);
d) SELECT * FROM employees WHERE salary > SUM(salary)/COUNT(*);

Answer: b) SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM
employees);

14. LIKE operator

Select employees whose name starts with ‘A’:


a) SELECT * FROM employees WHERE name LIKE 'A%';
b) SELECT * FROM employees WHERE name LIKE '%A';
c) SELECT * FROM employees WHERE name LIKE '%A%';
d) SELECT * FROM employees WHERE name = 'A%';

Answer: a) SELECT * FROM employees WHERE name LIKE 'A%';

15. IN operator

Select employees in departments 1, 2, or 3:


a) SELECT * FROM employees WHERE department IN (1,2,3);
b) SELECT * FROM employees WHERE department = (1,2,3);
c) SELECT * FROM employees WHERE department = IN (1,2,3);
d) SELECT * FROM employees WHERE department BETWEEN 1 AND 3;

Answer: a) SELECT * FROM employees WHERE department IN (1,2,3);


16. NOT IN

Select employees NOT in departments 1 and 2:


a) SELECT * FROM employees WHERE department NOT IN (1,2);
b) SELECT * FROM employees WHERE department != IN (1,2);
c) SELECT * FROM employees WHERE department <> (1,2);
d) SELECT * FROM employees WHERE department NOT = (1,2);

Answer: a) SELECT * FROM employees WHERE department NOT IN (1,2);

17. BETWEEN

Select employees with salary between 2000 and 5000:


a) SELECT * FROM employees WHERE salary >= 2000 AND salary <= 5000;
b) SELECT * FROM employees WHERE salary BETWEEN 2000 AND 5000;
c) SELECT * FROM employees WHERE salary = 2000 TO 5000;
d) Both a & b

Answer: d) Both a & b

18. IS NULL

Select employees with no department assigned:


a) SELECT * FROM employees WHERE department = NULL;
b) SELECT * FROM employees WHERE department IS NULL;
c) SELECT * FROM employees WHERE department = 'NULL';
d) SELECT * FROM employees WHERE department IS EMPTY;

Answer: b) SELECT * FROM employees WHERE department IS NULL;

19. IS NOT NULL

Select employees with a department:


a) SELECT * FROM employees WHERE department IS NOT NULL;
b) SELECT * FROM employees WHERE department != NULL;
c) SELECT * FROM employees WHERE department <> NULL;
d) SELECT * FROM employees WHERE department = NOT NULL;
Answer: a) SELECT * FROM employees WHERE department IS NOT NULL;

20. Aliases

Which query gives emp_name as an alias for name?


a) SELECT name AS emp_name FROM employees;
b) SELECT name TO emp_name FROM employees;
c) SELECT name emp_name FROM employees;
d) SELECT name ALIAS emp_name FROM employees;

Answer: a) SELECT name AS emp_name FROM employees;

21. PRIMARY KEY

Which column ensures unique values and no NULLs?


a) FOREIGN KEY
b) PRIMARY KEY
c) UNIQUE
d) CHECK

Answer: b) PRIMARY KEY

22. FOREIGN KEY

Which defines a link to another table?


a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) DEFAULT

Answer: b) FOREIGN KEY

23. UNIQUE

Which ensures column values are unique but allows NULLs?


a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) CHECK

Answer: c) UNIQUE

24. CHECK

Which ensures salary > 0?


a) CHECK(salary > 0)
b) CONSTRAINT(salary > 0)
c) UNIQUE(salary > 0)
d) VALIDATE(salary > 0)

Answer: a) CHECK(salary > 0)

25. DEFAULT

Set default salary to 3000:


a) salary DEFAULT 3000
b) salary SET 3000
c) salary ASSIGN 3000
d) salary INIT 3000

Answer: a) salary DEFAULT 3000

26. SQL Functions

Which returns the number of rows?


a) SUM()
b) AVG()
c) COUNT()
d) MAX()

Answer: c) COUNT()

27. CONCAT
Concatenate first and last name:
a) SELECT first_name + last_name FROM employees;
b) SELECT CONCAT(first_name, last_name) FROM employees;
c) SELECT first_name & last_name FROM employees;
d) SELECT MERGE(first_name, last_name) FROM employees;

Answer: b) SELECT CONCAT(first_name, last_name) FROM employees;

28. SQL Comment

Which is correct single-line comment?


a) -- This is a comment
b) /* This is a comment */
c) # This is a comment
d) All of the above

Answer: d) All of the above

29. SQL Wildcards

% in LIKE represents:
a) Single character
b) Any number of characters
c) Only digits
d) Nothing

Answer: b) Any number of characters

30. SQL Injection Prevention

Which method prevents SQL injection?


a) Use parameterized queries
b) Use string concatenation
c) Use dynamic SQL
d) Allow direct user input

Answer: a) Use parameterized queries

You might also like