0% found this document useful (0 votes)
57 views24 pages

SQL - Milestone Assesment1 - MCQ - Final - 30

This JSON contains summaries of multiple document questions about SQL and database concepts. The questions cover topics such as JOINs, aggregation, NULL values, wildcard characters in LIKE clauses, and modifying database objects. Appropriate SQL statements are also discussed.

Uploaded by

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

SQL - Milestone Assesment1 - MCQ - Final - 30

This JSON contains summaries of multiple document questions about SQL and database concepts. The questions cover topics such as JOINs, aggregation, NULL values, wildcard characters in LIKE clauses, and modifying database objects. Appropriate SQL statements are also discussed.

Uploaded by

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

Questions Options (A) Options (B)

Please read the question carefully and choose ON DELETE CASCADE ON DELETE SET NULL
the most appropriate option. To automatically
delete rows in a child table when a parent record
is deleted use:

Please read the question carefully and choose SELECT CustomerName, SELECT CustomerName,
the most appropriate option. Which of the COUNT(CustomerName) FROM COUNT(CustomerName)
following SQL statements is correct? Orders ORDER BY CustomerName FROM Orders GROUP BY
CustomerName

Please read the question carefully and choose UPDATE employees SET first_name UPDATE employees SET
the most appropriate option. Examine the = 'John' AND last_name ='Smith' first_name = 'John' SET
structure of the EMPLOYEES table: WHERE employee_id = 180; last_name ='Smith'
EMPLOYEE_ID NUMBER Primary Key WHERE employee_id =
FIRST_NAME VARCHAR2(25) 180;
LAST_NAME VARCHAR2(25)
HIRE_DATE DATE
Which UPDATE statement is valid?

Please read the question carefully and choose None WHERE


the most appropriate option. The CUSTOMERS lower(country_address) =
table has these columns: "france"
CUSTOMER_ID NUMBER(4) NOT NULL
CUSTOMER_NAME VARCHAR2(100) NOT NULL
STREET_ADDRESS VARCHAR2(150)
CITY_ADDRESS VARCHAR2(50)
STATE_ADDRESS VARCHAR2(50)
PROVINCE_ADDRESS VARCHAR2(50)
COUNTRY_ADDRESS VARCHAR2(50)
POSTAL_CODE VARCHAR2(12)
CUSTOMER_PHONE VARCHAR2(20)
A sale is being advertised to the customers in
France. Which WHERE clause
identifies customers that are located in France?
Examine the description of the EMPLOYEES SELECT dept_id, job_cat, SELECT dept_id, job_cat,
table: MAX(salary) FROM employees MAX(salary) FROM
WHERE salary > MAX(salary); employees GROUP BY
EMP_ID NUMBER(4) NOT NULL job_cat, dept_id;
LAST_NAME VARCHAR2(30) NOT NULL
FIRST_NAME VARCHAR2(30)
DEPT_ID NUMBER(2)
JOB_CAT VARCHARD2(30)
SALARY NUMBER(8,2)

Which statement shows the maximum salary


paid in each job category of each
department?

You created a view called EMP_DEPT_VU that ALTER VIEW emp_dept_vu (ADD MODIFY VIEW
contains three columns from the manager_id NUMBER); emp_dept_vu (ADD
EMPLOYEES and DEPARTMENTS tables: manager_id NUMBER);

EMPLOYEE_ID, EMPLOYEE_NAME AND


DEPARTMENT_NAME.

The DEPARTMENT_ID column of the EMPLOYEES


table is the foreign key to the
primary key DEPARTMENT_ID column of the
DEPARTMENTS table.

You want to modify the view by adding a fourth


column, MANAGER_ID of NUMBER
data type from the EMPLOYEES tables.

How can you accomplish this task?


Examine the data from the ORDERS and SELECT ord_id, cust_id, ord_total SELECT ord_id, cust_id,
CUSTOMERS table. FROM orders, customers ord_total FROM orders
WHERE cust_name=’Mating’ Where ord_date IN
ORDERS AND ord_date IN (’18-JUL- (SELECT ord_date
ORD_ID ORD_DATE CUST_ID ORD_TOTAL 2000’,’21-JUL-2000’); FROM orders WHERE
100 12-JAN-2000 15 10000 cust_id = (SELECT cust_id
101 09-MAR-2000 40 8000 FROM customers WHERE
102 09-MAR-2000 35 12500 cust_name = ‘Martin’));
103 15-MAR-2000 15 12000
104 25-JUN-2000 15 6000
105 18-JUL-2000 20 5000
106 18-JUL-2000 35 7000
107 21-JUL-2000 20 6500
108 04-AUG-2000 10 8000

CUSTOMERS
CUST_ID CUST_NAME CITY
10 Smith Los Angeles
15 Bob San Francisco
20 Martin Chicago
25 Mary New York
30 Rina Chicago
35 Smith New York
40 Linda New York

Which SQL statement retrieves the order ID,


customer ID, and order total for the
orders that are placed on the same day that
Martin places his orders?
Examine the description of the CUSTOMERS SELECT city_address, COUNT(*) SELECT city_address,
table: FROM customers WHERE COUNT(*) FROM
city_address IN ('Los customers WHERE
CUSTOMER_ID NUMBER(4) NOT NULL Angeles', 'San Francisco'); city_address IN ('Los
CUSTOMER_NAME VARCHAR2(100) NOT NULL Angeles', 'San Francisco')
STREET_ADDRESS VARCHAR2(150) GROUP BY city_address;
CITY_ADDRESS VARCHAR2(50)
STATE_ADDRESS VARCHAR2(50)
PROVINCE_ADDRESS VARCHAR2(50)
COUNTRY_ADDRESS VARCHAR2(50)
POSTAL_CODE VARCHAR2(12)
CUSTOMER_PHONE VARCHAR2(20)

The CUSTOMER_ID column is the primary key for


the table.
Which statement returns the city address and
the number of customers in the cities Los
Angeles or San Francisco?

The STUDENT_GRADES table has these columns: SELECT MAX(gpa) FROM SELECT (gpa) FROM
student_grades WHERE gpa IS NOT student_grades GROUP BY
STUDENT_ID NUMBER(12) NULL; semester_end WHERE gpa
SEMESTER_END DATE IS NOT
GPA NUMBER(4,3) NULL;

Which statement finds the highest grade point


average (GPA) per semester?

Which clause should you use to exclude group WHERE HAVING


results?
Examine the description of the STUDENTS table: SUM(start_date) AVG(start_date)
STD_ID NUMBER(4)
COURSE_ID VARCHARD2(10)
START_DATE DATE
END_DATE DATE

Which two aggregate functions is valid on the


START_DATE column?
Statement 1: Statement 1 Statement 2
SELECT last_name, salary, hire_date FROM
EMPLOYEES ORDER BY salary DES limit 2;

Statement 2:
SELECT last_name, salary, hire_date FROM
EMPLOYEES ORDER BY salary limit 2;

Statement 3:
SELECT last_name, salary, hire_date FROM
EMPLOYEES ORDER BY 2 DESC limit 2;

Statement 4:
SELECT last_name, salary, hire_date FROM
EMPLOYEES ORDER BY 2 limit 2;

Which among above statement(s) will give you


result as ‘top 2 salaried employees’?

Examine the description of the MARKS table: The statement executes The statement returns an
successfully and returns the error
STD_ID INT student ID and sum of all marks
STUDENT_NAME VARCHAR(30) for each student who obtained
SUBJ1 INT more than the average mark in
SUBJ2 INT each subject.

SUBJ1 and SUBJ2 indicate the marks obtained by


a student in two subjects.

Examine this SELECT statement based on the


MARKS table:

SELECT subj1+subj2 total_marks, std_id


FROM marks WHERE subj1 > AVG(subj1) AND
subj2 > AVG(subj2)
ORDER BY total_marks;

What is the result of the SELECT statement?


The EMP table contains these columns: The operator in the WHERE clause The column in the WHERE
should be changed to display the clause should be changed
LAST NAME VARCHAR(25) desired results. to display the desired
SALARY INT results.
DEPARTMENT_ID INT

You need to display the employees who have


not been assigned to any department.
You write the SELECT statement:

SELECT LAST_NAME, SALARY, DEPARTMENT_ID


FROM EMP
WHERE DEPARTMENT_ID = NULL;

What is true about this SQL statement?

Please read the question carefully and choose LIKE ...... (that's six dots) LIKE ??????
the most appropriate option. In a LIKE clause,
you can ask for any 6 letter value by writing?

Please read the question carefully and choose create a new table in the database modify an existing table in
the most appropriate option. The SQL DROP a database
TABLE clause is used to...

Please read the question carefully and choose 5 15


the most appropriate option. If table A have 10
rows and table B have 5 rows, how many rows
will be returned if you perform a cartesian join
on those two tables?

Which statement selects the employee details SELECT * FROM employee SELECT * FROM employee
whose first name starts with 'S' followed by any WHERE first_name LIKE '%S_s%'; WHERE first_name LIKE
one character. Third character should be 's' 'S_s%';
followed by any characters.

Select the statement that shows the employees' SELECT first_name, department_id, SELECT first_name,
name, department id , job id and the salary of job_id, salary department_id, job_id,
the employees working in department 80 and FROM employees salary
their job ascending and the salary in descending WHERE department_id = 80 FROM employees
order ORDER BY job_id ASC, salary DESC; WHERE department_id =
80
ORDER BY salary ASC,
job_id DESC ;
Which statement generates a report from SELECT employee_id || is || SELECT employee_id is
employee tables for all employees as follows last_name last_name
|| and works as ||job_id and works as job_id
101 is King and works as AD_PRES with salary of || with salary of Rs ||salary with salary of Rs salary
Rs 24000 FROM employees; FROM employees;

Select all employees who are working in SELECT * FROM employees SELECT * FROM
department 30 as job_id 'PU_CLERK' WHERE department_id IN 30 employees
AND job_id ('PU_CLERK'); WHERE department_id IN
30
OR job_id = 'PU_CLERK';

Calculate the total salary of employees on depar SELECT department_id, SELECT department_id,
SUM(salary) SUM(salary)
FROM employees FROM employees
GROUP BY department_id; HAVING department_id;

Select only the groups which are having total SELECT department_id, SELECT department_id,
salary greater than 13,000/- SUM(salary) SUM(salary)
FROM employees FROM employees
GROUP BY department_id GROUP BY department_id
ORDER BY department_id; HAVING SUM(salary) >
13000;

SELECT department_id FROM employees All distinct rows selected by the all rows selected by either
INTERSECT first query,
SELECT department_id FROM departments; query but not the second query including all duplicates

The above query returns

Display all departments, including those SELECT d.department_id, SELECT d.department_id,


departments without any employees e.last_name e.last_name
FROM departments d LEFT OUTER FROM departments d
JOIN employees e RIGHT OUTER JOIN
ON d.department_id = employees e
e.department_id; ON d.department_id =
e.department_id;

The below query is an example for Equi-join Non-Equi-Join

SELECT employee_id, first_name,


department_name
FROM employees, departments;
Display all employees who are not eligible for SELECT * FROM employees SELECT * FROM
commission WHERE commission_pct IS NULL; employees
WHERE commission_pct =
NULL;

Add a new column - mark NUMBER(4) - to ALTER TABLE student ALTER TABLE student
student table MODIFY mark NUMBER(4); ADD (mark NUMBER(4));

What is INLINE VIEW A subquery in the WHERE clause of A subquery in the GROUP
a SELECT statement BY clause of a SELECT
statement

To partially rollback the changes of a transaction COMMIT Rollback


use
Options (C) Options (D) Correct Answer
ON DELETE ORPHAN None of the listed options ON DELETE CASCADE

SELECT CustomerName, None of the Above SELECT CustomerName,


COUNT(CustomerName) COUNT(CustomerName) FROM
FROM Orders Orders GROUP BY CustomerName

UPDATE employees SET UPDATE employees SET first_name = UPDATE employees SET first_name
first_name = 'John', SET 'John', last_name ='Smith' WHERE = 'John', last_name ='Smith'
last_name ='Smith' WHERE employee_id = 180; WHERE employee_id = 180;
employee_id = 180;

WHERE WHERE lower(country_address) = WHERE lower(country_address) =


lower(country_address) IS 'france' 'france'
'france'
SELECT dept_id, job_cat, SELECT dept_id, job_cat, MAX(salary) SELECT dept_id, job_cat,
MAX(salary) FROM FROM employees GROUP BY dept_id, MAX(salary) FROM employees
employees; job_cat, salary; GROUP BY job_cat, dept_id;

CREATE OR REPLACE VIEW You must remove the existing view CREATE OR REPLACE VIEW
emp_dept_vu AS first, and then run the CREATE VIEW emp_dept_vu AS
SELECT employee_id, command SELECT employee_id,
employee_name, with a new column list to modify a employee_name,
department_name, view department_name, manager_id
manager_id FROM employees e, departments
FROM employees e, d WHERE e.department_id =
departments d WHERE d.department_id;
e.department_id =
d.department_id;
SELECT ord_id, cust_id, SELECT ord_id, cust_id, ord_total SELECT ord_id, cust_id, ord_total
ord_total FROM orders FROM orders FROM orders
Where ord_date IN (SELECT WHERE cust_id IN (SELECT cust_id Where ord_date IN (SELECT
ord_date FROM orders, FROM customers ord_date
customers WHERE cust name = ‘Martin’); FROM orders WHERE cust_id =
Where cust_name = (SELECT cust_id
‘Martin’); FROM customers WHERE
cust_name = ‘Martin’));
SELECT city_address, SELECT city_address, SELECT city_address, COUNT(*)
COUNT(customer_id) FROM COUNT(customer_id) FROM customers FROM customers WHERE
customers WHERE GROUP BY city_address city_address IN ('Los
city_address IN IN ('Los Angeles', 'San Francisco'); Angeles', 'San Francisco') GROUP
('Los Angeles', 'San BY city_address;
Francisco') GROUP BY
city_address, customer_id;

SELECT MAX(gpa) FROM SELECT MAX(gpa) GROUP BY SELECT MAX(gpa) FROM


student_grades WHERE gpa semester_end WHERE gpa IS NOT student_grades WHERE gpa IS
IS NOT NULL GROUP BY NULL FROM NOT NULL GROUP BY
semester_end; student_grades; semester_end;

RESTRICT GROUP BY HAVING

COUNT(start_date) MAXIMUM(start_date) COUNT(start_date)


Statement 3 Statement 4 Statement 3

he statement executes None of the above The statement returns an error


successfully and returns the
student ID and AVG of all
marks
The SQL statement displays The WHERE clause should be changed The operator in the WHERE clause
the desired results. to use an outer join to display the should be changed to display the
desired desired results.
results.

LIKE .{6} Answer 5: LIKE ^. LIKE ______ (that's six underscore LIKE ______ (that's six underscore
{6}$ characters) characters)

delete a table from the Removes All rows from the table delete a table from the database
database

10 50 50

SELECT * FROM employee SELECT * FROM employee SELECT * FROM employee


WHERE first_name = 'S_s%'; WHERE first_name NOT LIKE 'S_s%'; WHERE first_name LIKE 'S_s%';

SELECT first_name, SELECT first_name, department_id, SELECT first_name,


department_id, job_id, salary job_id, salary department_id, job_id, salary
FROM employees FROM employees FROM employees
WHERE department_id = 80 WHERE department_id = 80 WHERE department_id = 80
ORDER BY job_id DESC ; ORDER BY job_id,salary; ORDER BY job_id ASC, salary DESC;
SELECT employee_id ||' is ' SELECT employee_id ,' is ' , last_name SELECT employee_id ||' is ' ||
|| last_name ,' and works as ',job_id last_name
||' and works as '||job_id ,' with salary of Rs ',salary ||' and works as '||job_id
||' with salary of Rs '||salary FROM employees; ||' with salary of Rs '||salary
FROM employees; FROM employees;

SELECT * FROM employees SELECT * FROM employees SELECT * FROM employees


WHERE department_id = 30 WHERE department_id = 30 WHERE department_id = 30
OR job_id = 'PU_CLERK'; AND job_id = 'PU_CLERK'; AND job_id = 'PU_CLERK';

SELECT SELECT department_id,job_id, SELECT department_id,


department_id,job_id, SUM(salary) SUM(salary)
SUM(salary) FROM employees FROM employees
FROM employees GROUP BY job_id,department_id; GROUP BY department_id;
GROUP BY department_id;

SELECT department_id, SELECT department_id, SUM(salary) SELECT department_id,


SUM(salary) FROM employees SUM(salary)
FROM employees GROUP BY department_id; FROM employees
GROUP BY department_id GROUP BY department_id
HAVING salary > 13000; HAVING SUM(salary) > 13000;

all distinct rows selected by only distinct rows that appear in either all distinct rows selected by
both queries result both queries

SELECT d.department_id, SELECT d.department_id, e.last_name SELECT d.department_id,


e.last_name FROM departments d, employees e e.last_name
FROM departments d FULL WHERE d.department_id = FROM departments d LEFT
OUTER JOIN employees e e.department_id; OUTER JOIN employees e
ON d.department_id = ON d.department_id =
e.department_id; e.department_id;

Outer Join Cartesian product Cartesian product


SELECT * FROM employees SELECT * FROM employees SELECT * FROM employees
WHERE commission_pct = WHERE commission_pct IS NOT NULL; WHERE commission_pct IS NULL;
'NULL';

ALTER TABLE student ALTER TABLE student ALTER TABLE student


INSERT (mark NUMBER(4)); DROP mark NUMBER(4); ADD (mark NUMBER(4));

A subquery in the ORDER BY A subquery in the FROM clause of a A subquery in the FROM clause of
clause of a SELECT statement SELECT statement a SELECT statement

Rollback to Savepoint All of these Rollback to Savepoint


Correct
Option
A

D
B

C
B
B

C
C

B
A

A
C

D
A

You might also like