SQL for Oracle
Comprehensive SQL quiz covering SELECT statements, DML operations, constraints, views, aliases, GROUP BY, HAVING, and complex queries with subqueries
Questions
Triggers are most useful to enforce which type of integrity?
- Referential integrity
- Entity integrity
- Domain integrity
- User-defined integrity
- None of these
Select * from employees where (total_sales-25000) between (select avg(total_sales) from employees) and (select avg(total_sales)*1.2 from employees);
What will be the output of the above query?
Table:
Employees(emp_id,fname,lname,salary,total_sales)
- It retrieves the details of employees whose total sales volume is greater than the average sales volume.
- It lists those employees whose total sales volume minus 25000 is between the average sales volume and 120 percent of the average.
- It lists those employees whose total sales volume minus 25000 is between the average sales and 1.2% of the sales.
- It lists those employees whose total sales volume minus 25000 is between the average sales and 1.2% of the average.
- None of these
Which of the following syntaxes is not correct for insert statement (consider table in description)?
Table: rolno(numeric),fname(varchar),mname(varchar),lname(varchar)
- INSERT INTO tableVALUES ('xyz', 'abc');
- INSERT INTO table fname, lnameVALUES 'xyz', 'abc';
- INSERT INTO table ('fname', 'lname')VALUES ('xyz', 'abc');
- INSERT INTO table (fname, lname)VALUES ('xyz', 'abc');
- INSERT INTO table (rolno, lname)VALUES (34, abc);
What would be the SQL query/queries to list the regno of examinees who have a score greater than the average score?
Table:
Examinee(regno,name,score)
Where regno is primary key.
- Select regno from examine where score>avg(score);
- Select regno, avg(score) from examine where score>avg(score);
- Select regno from examine where score>(select avg(score) from examinee);
- All of the above
- None of these
What will be the SQL query to retrieve the sp and cp of all products whose item (name) is not entered?
Table:Product(id,item,sp,cp)
- Select sp,cp from product where item is NULL;
- Select sp,cp from product where item = NULL;
- Select sp,cp from product where item = 0;
- All of the above
- None of these
Which of the following syntaxes is not correct for column or table aliasing in SQL?
- Select id,item,(sp-cp) as profit from product;
- Select id,item,(sp-cp) profit from product;
- Select id,item,(sp-cp)=profit from product;
- Select id,p.item, from product p;
- None of these
What is the difference between drop and delete?
- Both remove columns from table.
- Both remove rows from table.
- DELETE Statement is used to remove rows in a table while drop removes a column in a table.
- Both work in a similar way.
- None of these
What will be the output of the following query?
select dept from employee e group by dept having (select count() from employee cs_e where e.dept = cs_e.dept and (position like %managers' or position like %supervisor or position like '%president%'))>(select count() from employees cs_e where e.dept = cs_e.dept and (position not like '%manager' and position not like '%supervisor%' and position not like 'president%')) order by dept;
Table:
Employee(emp_id,fname,lname,dept,position)
- It will display the name of the departments that have managers, supervisors and president.
- It will display the name of the departments that have more employees with job titles such as managers, supervisors or president than not.
- It will display the name of the departments that have manager, assistant manager, supervisor, vice president or president.
- It will display the name of the departments that have more employees with job titles such as managers, assistant manager, supervisors, vice president or president than not.
- None of these
Which of the following statements is/are true about having and group by clause?
(a) Group by clause can work alone.
(b) Having clause can work alone.
(c) If group by clause is used, then having clause must be used in a query.
(d) The having clause is used only if group by clause is used in a query.
- Only c
- a and b
- a, b, c and d
- a and d
- None of these
Select distinct name from students, courses, grades where
students.roll_no = grade.roll_no and courses.instructor = Korth and courses.course_no = grades.course_no and grades.grade = A;
Which of the following sets is computed by the above query?
Tables:
Students(roll_no,name,dob)
Courses(course_no,course_name,instructor)
Grades(roll_no,course_no,grade)
- Names of students who have got an A grade in all courses.
- Names of students who have got an A grade in all courses taught by Korth.
- Names of students who have got an A grade in at least one of the courses taught by Korth.
- Names of students who have got an A grade in at least one of the courses.
- None of these
Which of the following is not true about the limitations of view?
- If you use the DISTINCT clause to create a view, you cannot update or insert records within that view.
- If you do insert or update records through a join view, all records that are updated must belong to the same physical table.
- Virtual columns can be updated.
- You cannot use DELETE statements on multiple table views.
- None of these
Which constraint is used to ensure that all the values in the column are different?
- NOT NULL constraint
- DEFAULT constraint
- PRIMARY key
- UNIQUE constraint
- FOREIGN key
What will be the output of the following SQL statement?
Select * from guest where guestno = (select guestno from booking where datefrom< = current_date and dateto> = current_date and hotelno = (select hotelno from hotel where hname = 'XYZ'));
Tables:
Guest(guestno,gname,gadd)
Hotel(hotelno,hname,city)
Booking(hotelno,guestno,datefrom,datto,roomno)
Room(roomno,hotelno,type,price)
- Guest details who are staying in XYZ hotel from the specific date to the current date.
- Guest details who are staying in XYZ hotel as on date.
- Guest details who are staying in XYZ hotel.
- Guest details who are not staying in XYZ hotel as on date.
- None of these
Which of the following statements is/are true?
(a) The where clause searches the rows after they are grouped by using 'group by' clause.
(b) The 'group by' clause collects rows that meet the where clause search conditions and places those rows into a group for each unique value in the ' group by' clause.
(c) Omitting the 'group by' clause creates a single group for the whole table.
Table1
NAME
ABLE
BAKER
CHARLIE
DEAN
Table2
NAME
ABLE
BAKER
BRAVO
CHARLIE
DECON
- a and b
- b and c
- a and c
- All of these
- Only b
Update inventory set price = price*.75 where not exists (select * from invoice_details i where inventory.item_no = i.item_number and inv_no in (select inv_no from invoices where inv_date> = getdate()-30));
The purpose of the above given query is
Tables:
Invoice_details(item,number,price,invoice_dat,inv_no)
Inventory(item_no,price,inv_date,....)
Invoices(inv_no,inv_date,....)
- to discount only those things that have sales since the inv_date
- to discount only those items that have had no sales within the last 30 months
- to gives 25% discount to only those items that have had sales within the past 30 days
- to discount only those items that have had no sales within the past 30 days
- None of these