Create sql procedure to print out names and grade of student

Assignment Help PL-SQL Programming
Reference no: EM13887555

Database used in the ASSIGNMENT:

You will be using the following tables in the exam.

drop table grades;
drop table student;
drop table teacher;
drop table class;

create table student(
sid integer, --- student ID
sname varchar(50), --- student name
primary key (sid));

create table teacher(
tid integer, --- teacher ID
tname varchar(50), ---- teacher name
primary key (tid));

create table class(
cid integer, --- class ID
cname varchar(50),--- class name
year integer, --- year of class
semester varchar(10), -- fall or spring
credit integer, -- number of credit
tid integer, --- teacher id
primary key (cid),
foreign key (tid) references teacher(tid));

create table grades(
sid integer, --- student ID
cid integer, --- product ID
grade integer, --- grade: 4.0:A, 3: B, 2: C, 1:D, 0:F
primary key (sid, cid),
foreign key (sid) references student(sid),
foreign key (cid) references class(cid));

insert into student values (1, 'John');
insert into student values (2, 'Alice');
insert into student values (3, 'Bob');
insert into student values (4, 'Cathy');
insert into student values (5, 'Jeff');

insert into teacher values (1, 'Dr. Chen');
insert into teacher values (2, 'Dr. Smith');

insert into class values(1,'IS 633', 2015, 'fall', 3,1);
insert into class values(2,'IS 633', 2014, 'fall', 3,1);
insert into class values(3,'IS 603', 2015, 'fall', 3,2);
insert into class values(4,'IS 603', 2015, 'spring', 3,2);

insert into grades values(1,1,4);
insert into grades values(2,1,3);
insert into grades values(4,1,2);

insert into grades values(3,2,3);
insert into grades values(5,2,4);

insert into grades values(1,3,4);
insert into grades values(5,3,3);

insert into grades values(2,4,3);
insert into grades values(3,4,2);
insert into grades values(4,4,4);

Problem 1: Please create a PL/SQL procedure to print out names and grade of students taking a given class in a given year and semester. The input parameters are the class name, year, and semester. There is no output parameter.

Problem 2: Please create a PL/SQL function to return the average grade of students taking a given class in a given year and semester. The input parameters are the class name, year, and semester. Please write an anonymous PL/SQL program to call the function and print out returned value if it is not null. Please check returned value when calling the function.

Problem 3: Please answer questions a and b on RAID levels.

a) Suppose you are given 6 data blocks and 4 disks in RAID level 10. Please fill in data blocks in the figure below. You can use 1, 2, ... to represent data blocks 1, 2, ....

 

Disk 1
Disk 2
Disk 3
Disk 4
 
 
 
 
 
 
 
 
 
 
 
 
Group 1
Group 2

b) Please decide for each of the following applications, which RAID level (level 0, 10, or 5) may be the most appropriate. Please also briefly explain your answers.

i. A flight control system. The system needs to handle many flights and the airplanes' positions are changing all the time.
ii. Storing temporary tables in a database. These tables are only used for a short period of time and will be discarded afterwards.
iii. A data warehouse for managers to analyze sales. Data is updated once a week.

Problem 4:

Please specify what indexes you want to create to speed up the SQL queries below. These queries use the database created on page 2 (you can assume the tables have many rows so indexes are needed). You need to specify the table and columns you want to index. You don't need to write create index statements. Please also briefly explain why you select this index. Your grade depends on both the index and explanation.

Query 1. select * from grades where grade < 2 and cid = 3;

Query 2. select * from student s, grades g where s.sid = g.sid;

Query 3. select sid, avg(grade) from grades group by sid;

Query 4. Select * from class where cname like '%633%';

Problem 5: Below is the schedule for three transactions T1, T2, and T3. Please briefly explain which transactions satisfy two-phase locking protocol and which don't. Your grade depends on both your answer and explanation. Each line is an operation starting with the transaction the operation belongs to. Lock-X(o) means request an exclusive lock on o. Lock-S(o) means request a shared lock on o. Unlock(o) means release the lock it holds on o.

T1                               T2                               T3

T1: Lock-X(A)          

T1: Read(A)  

T1: A := A - 50         

T1: Write(A) 

T1: Unlock(A)          

                                                                        T3: Lock-S(A)

                                                                        T3: Read(A)

                                                                        T3: Print(A)

                                                                        T3: Unlock(A)

 

T2: Lock-S(B)

                                    T2: Read(B)

                                    T2: Print(B)

                                    T2: Unlock(B)                                                                       

T1: Lock-X(B)          

T1: Read(B)  

T1: B : = B + 50        

T1: Write(B) 

T1: Unlock(B)

Problem 6: Please briefly explain whether the following schedule has a deadlock. Your grade depends on both your answer and explanation. T1, T2, and T3 are 3 transactions. A, B, and C are 3 database rows. Lock-X means requesting an exclusive lock, Lock-S means requesting a shared lock. If you draw a wait-for graph, you will get partial credits even if your answer is wrong.

T1                                T2                                T3             

T1: Lock-X(C)                       

T1: Write(C)             

                                     T2: Lock-X(B)           

                                    T2: Write(B)  

                                                                        T3: Lock-S(A)

T3: Read(A)

                                                                        T3: Lock-S(C)

T1: Lock-S(B)                                               

                                    T2: Lock-S(A)

                                    T2: Read(A)   

Problem 7: For each of the following statement, decide whether it is true or false. Please use a sentence or two to explain why. The grade depends on both your answer and explanation. [20 points, 4 points per question]

1. Based on the following parameters, disk 1 is faster than disk 2.
Disk 1: seek time 2 milliseconds, 10000 rpm
Disk 2: seek time 3 milliseconds, 7200 rpm

2. Query optimization is done manually by the database administrator because DBA knows how to optimize a query.

3. If a transaction T1 already gets a shared lock on a data item A, and there is no other transaction that has a lock on A, T1 can get an exclusive lock on A.

4. To find out whether an index is used by a SQL query, you can do the following: 1) run the query when the index is not created; 2) create the index; 3) run the same query again and check whether the query runs faster after the index is created. If so the index is used.

5. Two-phase locking protocol not only ensures that concurrent execution of transactions will give correct results, but also prevents deadlock.

Reference no: EM13887555

Questions Cloud

Why is given paper important to auditors : Why is this paper important to auditors, and what are the implications of this paper for the auditing profession? Describe the research methodology used as a basis for the conclusions.
Compute their itemized deduction for medical expenses : Mr. and Mrs. Moss, ages 70 and 64, have major medical and dental insurance provided by Mrs. Moss's employer. This year, they incurred the following unreimbursed expenses: Routine office visits to doctors and dentists ...$940 Emergency room visits...4..
Minimize the likelihood of centerline bursts : A high-strength steel bar must be cold-reduced from a diameter of 1.00 in. to 0.65 in. A number of schedules have been proposed. Which of the schedules below would you choose to avoid drawing failure and minimize the likelihood of centerline burst..
Out­line the limits of the agency''s discretion : This DT is a bit long, so bear with me.  There is a question here somewhere.   The courts have seriously considered the extent to which Congress can delegate its powers to third parties only in this century. In 1904, the United States Supreme Court f..
Create sql procedure to print out names and grade of student : Please create a PL/SQL function to return the average grade of students taking a given class in a given year and semester. The input parameters are the class name, year, and semester. Please write an anonymous PL/SQL program to call the function a..
What is pcaobs source of potential violations of pcaob rules : What is the PCAOB's source of potential violations of law or PCAOB rules? What is the PCAOB and what authority does it have to issue disciplinary orders and impose sanctions?
What are the possible remedies available to leho : Lehor is an antique car collector. He contracts to purchase spare parts for a 1938 engine from Beem. These parts are not made anymore and are scarce. To get the contract with Beem, Lehor agrees to pay 50% of the purchase price in advance. On May 1, L..
Philosophical and practical approach for balancing issues : Assignment on Philosophical and Practical Approach for Balancing Issues
Foreman favored higher reductions : The project engineer, the shop foreman, and a consultant met to discuss the problem. The consultant proposed applying forward and back tension during rolling, the project engineer suggested reducing the reduction per pass, and the shop foreman fav..

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Create a database model

Create a database model and Submit the table creation statements for the Database Model.

  Write pl-sql procedures and functions

Write PL/SQL procedures and functions to populate and query that database

  Sql questions

Write a query to display using the employees table the EMPLOYEE_ID, FIRST_NAME, LAST_NAME and HIRE_DATE of every employee who was hired after to 1 January, 1995.

  Run the lab_03_01.sql script

Run the lab_03_01.sql script in the attached file to create the SAL_HISTORY table. Display the structure of the SAL_HISTORY table.

  Write sql queries

Write a query to display the last name, department number, and salary of any employee whose department number and salary both match the department number and salary of any employee who earns a commission.

  Explaining sql insert statement to insert new row in cds

Write down a SQL insert statement to insert new row in "CDS" table.

  Write down name of actors in ascending order

Write down actors (or actress, your choice, but not both) who have won at least two (2) Academy Awards for best actor/actress. Provide the actor name, movie title & year. Order the result by actor name."

  What is an sql injection attack

What is an SQL injection attack? Explain how it works, and what precautions must be taken to prevent SQL injection attacks.What are two advantages of encrypting data stored in the database?

  Determine resonant frequency in series rlc resonant circuit

Given the series RLC resonant circuit in the figure, operating at variable frequency, determine: The resonant frequency ω o ,  The circuit’s quality factor Q , The cut-off frequencies, f 1  & f 2  and the bandwidth BW

  Query that uses cube operator to return lineitemsum

Write summary query which uses CUBE operator to return LineItemSum (which is the sum of InvoiceLineItemAmount) group by Account(an alias for AccountDesciption).

  Query to show customers were missing for existing orders

As DBA, your manager called a meeting and asked why there are so many orders for customers that don't exist in the customer table. Write query which would shows which customers were missing for existing orders. Use a join or a subquery.

  Sql query into a relational algebra statement

Turn this SQL query into a relational algebra statement? SELECT Request.reqfor, Ordering.invamt, Ordering.invnbr, Ordering.invdat

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd