0% found this document useful (0 votes)
24 views

SQL MCQ

1. John manages an employee database and needs to perform various CRUD operations on the "employees" table using SQL statements. 2. The document provides examples of SQL statements to add, update, delete, select, and perform other operations on the employee data in the database. 3. Fifteen multiple choice questions are provided to test understanding of the appropriate SQL statements to use for common tasks like adding a new employee, updating salaries, sorting data, and more.

Uploaded by

janet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

SQL MCQ

1. John manages an employee database and needs to perform various CRUD operations on the "employees" table using SQL statements. 2. The document provides examples of SQL statements to add, update, delete, select, and perform other operations on the employee data in the database. 3. Fifteen multiple choice questions are provided to test understanding of the appropriate SQL statements to use for common tasks like adding a new employee, updating salaries, sorting data, and more.

Uploaded by

janet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL MCQ

Employee Table

ID First Name Last Name Salary

1 Walter White 50000

2 Jane Smith 60000

3 Alice Johnson 55000

4 Bob Brown 52000

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

should he use? Options:

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

this update? Options:

A. John should run: UPDATE employees SET salary = 58000 WHERE id = 4;


B. John should run: UPDATE employees SET salary = 58000 WHERE last_name = 'Johnson'; C. John
should run: UPDATE employees SET salary = 58000 WHERE id = 3;
D. John should run: UPDATE employees SET salary = 58000 WHERE first_name = 'Alice';

4.John wants to remove an employee with ID 2 from the "employees" table. What SQL statement should he use?

Options:

A. John should run: DELETE FROM employees WHERE id = 2;


B. John should run: REMOVE FROM employees WHERE id = 2;
C. John should run: DELETE employees WHERE id = 2;
D. John should run: DROP FROM employees WHERE id = 2;

5.John needs to retrieve the count of all employees in the "employees" table. What SQL statement should he
use?

Options:

A. John should run: COUNT(*) FROM employees;


B. John should run: SELECT * FROM employees COUNT;
C. John should run: SELECT COUNT(*) FROM employees;
D. John should run: SELECT COUNT FROM employees;

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:

A. John should run: ALTER employees UPDATE first_name = 'Robert' WHERE id = 4;


B. John should run: UPDATE employees SET first_name = 'Robert' WHERE id = 4;
C. John should run: MODIFY employees SET first_name = 'Robert' WHERE id = 4;
D. John should run: CHANGE employees SET first_name = 'Robert' WHERE id = 4;

8.John needs to retrieve all employees with a last name containing the letter "a." What SQL statement should he
use?

Options:

A. John should run: SELECT * FROM employees WHERE last_name = 'a';


B. John should run: SELECT * FROM employees WHERE last_name LIKE '%a%';
C. John should run: SELECT * FROM employees WHERE last_name CONTAINS 'a';
D. John should run: SELECT * FROM employees WHERE last_name LIKE 'a';

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:

A. John should run: SELECT AVG(salary) FROM employees;


B. John should run: SELECT SUM(salary) FROM employees;
C. John should run: SELECT AVG(employee_salary) FROM employees;
D. John should run: SELECT AVERAGE(salary) FROM employees;

11.John wants to sort the employees by salary in descending order. What SQL statement should he use?

Options:

A. John should run: SELECT * FROM employees SORT BY salary DESC;


B. John should run: SELECT * FROM employees ORDER BY salary ASC;
C. John should run: SELECT * FROM employees SORT BY salary ASC;
D. John should run: SELECT * FROM employees ORDER BY salary DESC;

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:

A. John should run: SELECT MAX(salary) FROM employees;


B. John should run: SELECT HIGHEST(salary) FROM employees;
C. John should run: SELECT MAXIMUM(salary) FROM employees;
D. John should run: SELECT TOP(salary) FROM employees;

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';

You might also like