SQL MCQ
SQL MCQ
Employee Table
John manages an employee database in MySQL, and he's trying to perform various CRUD operations
on his "employees" table.
1.John wants to add a new employee, Sarah Davis, to his database with a salary of $58,000. Which
SQL statement should he use?
Options:
A. John should run: INSERT INTO employees (first_name, last_name, salary) SET ('Sarah', 'Davis',
58000); B. John should run: INSERT INTO employees (id, first_name, last_name, salary) VALUES
(NULL, 'Sarah', 'Davis', 58000);
C. John should run: INSERT INTO employees (first_name, last_name, salary) VALUES ('Sarah', 'Davis',
58000); D. John should run: UPDATE employees SET first_name = 'Sarah', last_name = 'Davis', salary =
58000;
2.John wants to see a list of employees with a salary greater than $55,000. What SQL statement
A. John should run: SELECT * FROM employees HAVING salary > 55000;
B. John should run: SELECT * FROM employees WHERE salary > 55000;
C. John should run: SELECT * FROM employees WHERE salary < 55000;
D. John should run: SELECT * FROM employees HAVING salary < 55000;
3.John needs to increase Alice Johnson's salary to $58,000. What is the correct SQL statement for
4.John wants to remove an employee with ID 2 from the "employees" table. What SQL statement should he use?
Options:
5.John needs to retrieve the count of all employees in the "employees" table. What SQL statement should he
use?
Options:
6.John wants to see a list of employees' first names and last names, sorted in ascending order by their last
names. What SQL statement should he use?
Options:
A. John should run: SELECT first_name, last_name FROM employees ORDER BY first_name ASC; B.
John should run: SELECT first_name, last_name FROM employees ORDER BY last_name ASC; C.
John should run: SELECT first_name, last_name FROM employees ORDER BY last_name DESC; D.
John should run: SELECT first_name, last_name FROM employees SORT BY last_name ASC;
7.John wants to change the first name of the employee with ID 4 from "Bob" to "Robert." Which SQL statement
should he use?
Options:
8.John needs to retrieve all employees with a last name containing the letter "a." What SQL statement should he
use?
Options:
9.John wants to add a new column named "department" to the "employees" table. Which SQL statement should
he use?
Options:
A. John should run: ALTER TABLE employees ADD COLUMN department VARCHAR(50);
B. John should run: UPDATE employees SET department = 'HR';
C. John should run: ADD COLUMN department TO employees;
D. John should run: ALTER employees ADD department COLUMN VARCHAR(50);
10.John needs to retrieve the average salary of all employees. What SQL statement should he use?
Options:
11.John wants to sort the employees by salary in descending order. What SQL statement should he use?
Options:
12.John wants to delete all employees with a salary less than $52,000. Which SQL statement should he use?
Options:
A. John should run: DELETE FROM employees WHERE salary < 52000;
B. John should run: REMOVE employees WHERE salary < 52000;
C. John should run: DELETE * FROM employees WHERE salary < 52000;
D. John should run: DELETE employees WHERE salary < 52000;
13.John wants to add a unique constraint to the "id" column in the "employees" table. What SQL statement
should he use?
Options:
A. John should run: ALTER TABLE employees ADD CONSTRAINT UNIQUE (id);
B. John should run: ALTER TABLE employees ADD UNIQUE KEY (id);
C. John should run: ALTER TABLE employees ADD UNIQUE (id);
D. John should run: ADD CONSTRAINT UNIQUE TO employees (id);
14.John wants to retrieve the highest salary among the employees. What SQL statement should he use?
Options:
15.John wants to update the salary of all employees with the last name "Smith" to $65,000. What is the correct
SQL statement for this update?
Options:
A. John should run: UPDATE employees SET salary = 65000 WHERE last_name = 'Smith'; B.
John should run: UPDATE employees SET salary = 65000 WHERE first_name = 'Smith'; C.
John should run: ALTER employees UPDATE salary = 65000 WHERE last_name = 'Smith'; D.
John should run: MODIFY employees SET salary = 65000 WHERE last_name = 'Smith';