SlideShare a Scribd company logo
Chapter 5
5.1 Describe
the circumstances in which you would choose to use embedded
SQL
rather than
SQL
alone or only a general-purpose programming language.
Answer:
5.2
Write a Java function using
JDBC
metadata features that takes a
ResultSet
as an input parameter, and prints out the result in tabular form,
with appropriate names as column headings.
Answer:
5.3
Write a Java function using
JDBC
metadata features that prints a list of all relations in the
database, displaying for each relation the names and types of its
attributes.
Answer:
5.4
Show how to enforce the constraint
“
an instructor cannot teach in two different classrooms in a
semester in the same time slot.
”
using a trigger (remember that the constraint can be violated by
changes to the
teaches
relation as well as to the
section
relation).
Answer:
5.5
Write triggers to enforce the referential integrity constraint
from
section
to
time
slot
, on updates to
section
, and
time
in Figure 5.8 do not cover the
update
operation.
slot
. Note that the ones we wrote
5.6
To maintain the
tot cred
attribute of the
student
relation, carry out the fol-
lowing:
a. Modify the trigger on updates of
takes
, to handle all updates that can
affect the value of
tot
b. Write a trigger to handle inserts to the
takes
relation.
cred
.
c. Under what assumptions is it reasonable not to create
triggers on the
course
relation?
Answer:
5.7
Consider the bank database of Figure 5.25. Let us define a view
branch cust
as follows:
create view
branch cust
as
select
branch name, customer name
from
depositor, account
where
depositor.account number
=
account.account number
Answer:
5.8
Consider the bank database of Figure 5.25. Write an
SQL
trigger to carry out the following action: On
delete
of an account, for each owner of the account, check if the owner
has any remaining accounts, and if she does not, delete her from
the
depositor
relation.
Answer:
5.9
Show how to express
group by cube
(
a
,
b
,
c
,
d
) using
rollup
; your answer should have only one
group by
clause.
Answer:
5.10
Given a relation
S
(
student
,
subject
,
marks
), write a query to find the top
n
students by total marks, by using ranking.
Answer:
5.11
Consider the
sales
relation from Section 5.6.Write an
SQL
query to compute the cube operation on the relation, giving the
relation in Figure 5.21. Do not use the
cube
construct.
Answer:
5.12
Consider the following relations for a company database:
•
emp
(
ename
,
dname
,
salary
)
•
mgr
(
ename
,
mname
) and the Java code in Figure 5.26, which uses the JDBC API.
Assume that the userid, password, machine name, etc. are all
okay. Describe in concise
English what the Java program does. (That is, produce an
English sentence like “It finds the manager of the toy
department,” not a line-by-line description of what each Java
statement does.)
Answer:
5.13
Suppose you were asked to define a class
MetaDisplay
in Java, containing a method
static void printTable(String r)
; the method takes a relation name
r
as input, executes the query
“
select
*
from
r
”
, and prints the result out in nice tabular format, with the
attribute names displayed in the header of the table.
import java.sql.*;
public class Mystery
{
public static void main(String[] args)
{
try
{
Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection(
"jdbc:oracle:thin:star/
[email protected]
//edgar.cse.lehigh.edu:1521/XE");
Statement s=con.createStatement();
String q;
String empName = "dog";
boolean more;
ResultSet result;
do
{
q = "select mname from mgr where ename = ’" + empName +
"’";
result = s.executeQuery(q);
more = result.next();
if (more)
{
empName = result.getString("mname");
System.out.println (empName);
}
}
while (more);
s.close();
con.close();
}
catch(Exception
e)
{
e.printStackTrace();
} }}
a. What do you need to know about relation
r
to be able to print the result in the specified tabular format.
b. What JDBC methods(s) can get you the required information?
c. Write the method
printTable(String r)
using the JDBC API.
Answer:
5.14
Repeat Exercise 5.13 using
ODBC
, defining
void printTable(char *r)
as a function instead of a method.
Answer:
5.15
Consider an employee database with two relations
employee
(
employee name
,
street
,
city
)
works
(
employee name
,
company name
,
salary
)
where the primary keys are underlined. Write a query to find
companies
whose employees earn a higher salary, on average, than the
average salary at
“
First Bank Corporation
”
.
a. Using SQL functions as appropriate.
b. Without using SQL functions.
Answer:
5.16
Rewrite the query in Section 5.2.1 that returns the name and
budget of all
departments with more than 12 instructors, using the
with
clause instead of using a function call.
Answer:
5.17
Compare the use of embedded
SQL
with the use in
SQL
of functions defined in a general-purpose programming
language. Under what circumstances would you use each of
these features?
Answer:
5.18
Modify the recursive query in Figure 5.15 to define a relation
prereq depth
(
course id
,
prereq id
,
depth
)
where the attribute
depth
indicates how many levels of intermediate prerequisites are
there between the course and the prerequisite. Direct
prerequisites have a depth of 0.
Answer:
5.19
Consider the relational schema
part
(
part id
,
name
,
cost
)
subpart
(
part id
,
subpart id
,
count
)
A tuple (
p
1
,
p
2
,
3) in the
subpart
relation denotes that the part with part-id
p
2 is a direct subpart of the part with part-id
p
1, and
p
1 has 3 copies of
p
2.
Note that
p
2 may itself have further subparts. Write a recursive SQL query
that outputs the names of all subparts of the part with part-id
“
P-100
”
.
Answer:
5.20
Consider again the relational schema from Exercise 5.19. Write
a
JDBC
function using non-recursive
SQL
to find the total cost of part
“
P-100
”
,including the costs of all its subparts. Be sure to take into
account the
fact that a part may have multiple occurrences of a subpart. You
may use
recursion in Java if you wish.
Answer:
5.21
Suppose there are two relations
r
and
s
, such that the foreign key
B
of
r
references the primary key
A
of
s
. Describe how the trigger mechanism can
be used to implement the
on delete cascade
option,when a tuple is deleted from
s
.
Answer:
5.22
The execution of a trigger can cause another action to be
triggered. Most database systems place a limit on how deep the
nesting can be. Explain why they might place such a limit.
Answer:
5.23
Consider the relation,
r
, shown in Figure 5.27. Give the result of the following query:
uilding
room
number
time
slot
id
course
id
sec
id
Garfield Garfield Saucon Saucon Painter Painter
359
359
651
550
705
403
A B A C D D
BIO-101 BIO-101 CS-101 CS-319 MU-199 FIN-201
1 2 2 1 1 1
select
building
,
room number
,
time slot id
,
count
(*)
from
r
group by rollup
(
building
,
room number
,
time slot id
)
Answer:
5.24
For each of the
SQL
aggregate functions
sum, count, min
, and
max
, show how to compute the aggregate value on a multiset
S
1
∪
S
2
, given the aggregate values on multisets
S
1
and
S
2
.
On the basis of the above, give expressions to compute
aggregate values with grouping on a subset
S
of the attributes of a relation
r
(
A
,
B
,
C
,
D
,
E
), given aggregate values for grouping on attributes
T
⊇
S
, for the following aggregate functions:
a.
sum, count, min,
and
max
b.
avg
c. Standard deviation
Answer:
5.25
In Section 5.5.1, we used the
student grades
view of Exercise 4.5 to write a query to find the rank of each
student based on grade-point average.
Modify that query to show only the top 10 students (that is,
those students whose rank is 1 through 10).
Answer:
5.26
Give an example of a pair of groupings that cannot be expressed
by using a single
group by
clause with
cube
and
rollup
.
5.27
Given relation
s
(
a
,
b
,
c
), show how to use the extended
SQL
features to generate a histogram of
c
versus
a
, dividing
a
into 20 equal-sized partitions
(that is, where each partition contains 5 percent of the tuples in
s
, sorted by
a
).
Answer:
5.28
Consider the bank database of Figure 5.25 and the
balance
attribute of the
account
relation. Write an
SQL
query to compute a histogram of
balance
values, dividing the range 0 to the maximum account balance
present, into three equal ranges.
Answer:

More Related Content

Similar to Chapter 55.1 Describe the circumstances in which you would c.docx

Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
Shakila Mahjabin
 
Bca3020 database management system
Bca3020   database management systemBca3020   database management system
Bca3020 database management system
smumbahelp
 
Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)
smumbahelp
 
JSF (ADF) Case Studies Presentation
JSF (ADF) Case Studies PresentationJSF (ADF) Case Studies Presentation
JSF (ADF) Case Studies Presentation
Michael Fons
 
UNIT 2 Structured query language commands
UNIT 2 Structured query language commandsUNIT 2 Structured query language commands
UNIT 2 Structured query language commands
Bhakti Pawar
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
Dr P Deepak
 
Smu bscit sem 3 spring 2015 assignments
Smu bscit sem 3 spring 2015 assignmentsSmu bscit sem 3 spring 2015 assignments
Smu bscit sem 3 spring 2015 assignments
solved_assignments
 
Bt0074 oop with java
Bt0074   oop with javaBt0074   oop with java
Bt0074 oop with java
smumbahelp
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
Sunil0108
 
SQL3.pdf
SQL3.pdfSQL3.pdf
SQL3.pdf
ssuser6101e9
 
Jsf intro
Jsf introJsf intro
Jsf intro
vantinhkhuc
 
CIS 407 STUDY Education Planning--cis407study.com
CIS 407 STUDY Education Planning--cis407study.comCIS 407 STUDY Education Planning--cis407study.com
CIS 407 STUDY Education Planning--cis407study.com
agathachristie300
 
2 rel-algebra
2 rel-algebra2 rel-algebra
2 rel-algebra
Mahesh Jeedimalla
 
Mi0041 java and web design
Mi0041   java and web designMi0041   java and web design
Mi0041 java and web design
smumbahelp
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
smumbahelp
 
E1
E1E1
E1
lksoo
 
Mca5033 open source db systems
Mca5033 open source db systemsMca5033 open source db systems
Mca5033 open source db systems
smumbahelp
 
Spring Certification Questions
Spring Certification QuestionsSpring Certification Questions
Spring Certification Questions
SpringMockExams
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
phanleson
 
Spring framework DAO
Spring framework  DAOSpring framework  DAO
Spring framework DAO
Anuj Singh Rajput
 

Similar to Chapter 55.1 Describe the circumstances in which you would c.docx (20)

Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
 
Bca3020 database management system
Bca3020   database management systemBca3020   database management system
Bca3020 database management system
 
Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)
 
JSF (ADF) Case Studies Presentation
JSF (ADF) Case Studies PresentationJSF (ADF) Case Studies Presentation
JSF (ADF) Case Studies Presentation
 
UNIT 2 Structured query language commands
UNIT 2 Structured query language commandsUNIT 2 Structured query language commands
UNIT 2 Structured query language commands
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
Smu bscit sem 3 spring 2015 assignments
Smu bscit sem 3 spring 2015 assignmentsSmu bscit sem 3 spring 2015 assignments
Smu bscit sem 3 spring 2015 assignments
 
Bt0074 oop with java
Bt0074   oop with javaBt0074   oop with java
Bt0074 oop with java
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
SQL3.pdf
SQL3.pdfSQL3.pdf
SQL3.pdf
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
CIS 407 STUDY Education Planning--cis407study.com
CIS 407 STUDY Education Planning--cis407study.comCIS 407 STUDY Education Planning--cis407study.com
CIS 407 STUDY Education Planning--cis407study.com
 
2 rel-algebra
2 rel-algebra2 rel-algebra
2 rel-algebra
 
Mi0041 java and web design
Mi0041   java and web designMi0041   java and web design
Mi0041 java and web design
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
 
E1
E1E1
E1
 
Mca5033 open source db systems
Mca5033 open source db systemsMca5033 open source db systems
Mca5033 open source db systems
 
Spring Certification Questions
Spring Certification QuestionsSpring Certification Questions
Spring Certification Questions
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
 
Spring framework DAO
Spring framework  DAOSpring framework  DAO
Spring framework DAO
 

More from DinahShipman862

Choose one ethical dilemma from each groupGroup A A newspaper c.docx
Choose one ethical dilemma from each groupGroup A A newspaper c.docxChoose one ethical dilemma from each groupGroup A A newspaper c.docx
Choose one ethical dilemma from each groupGroup A A newspaper c.docx
DinahShipman862
 
Choose one of the following artworks or artists for your Final Rep.docx
Choose one of the following artworks or artists for your Final Rep.docxChoose one of the following artworks or artists for your Final Rep.docx
Choose one of the following artworks or artists for your Final Rep.docx
DinahShipman862
 
Choose between1. Your company wants to export cultural artifacts .docx
Choose between1. Your company wants to export cultural artifacts .docxChoose between1. Your company wants to export cultural artifacts .docx
Choose between1. Your company wants to export cultural artifacts .docx
DinahShipman862
 
Choose at least two (2) items or events that you would consider to b.docx
Choose at least two (2) items or events that you would consider to b.docxChoose at least two (2) items or events that you would consider to b.docx
Choose at least two (2) items or events that you would consider to b.docx
DinahShipman862
 
Choose any song you wish (contemporary is fine). Look up the lyrics .docx
Choose any song you wish (contemporary is fine). Look up the lyrics .docxChoose any song you wish (contemporary is fine). Look up the lyrics .docx
Choose any song you wish (contemporary is fine). Look up the lyrics .docx
DinahShipman862
 
Choose any medicalhealthcare research institute and describe the or.docx
Choose any medicalhealthcare research institute and describe the or.docxChoose any medicalhealthcare research institute and describe the or.docx
Choose any medicalhealthcare research institute and describe the or.docx
DinahShipman862
 
Choose any aspect of the population geographydemographic landscape .docx
Choose any aspect of the population geographydemographic landscape .docxChoose any aspect of the population geographydemographic landscape .docx
Choose any aspect of the population geographydemographic landscape .docx
DinahShipman862
 
Choose a service type from Table 21.1 (Service Management chapter un.docx
Choose a service type from Table 21.1 (Service Management chapter un.docxChoose a service type from Table 21.1 (Service Management chapter un.docx
Choose a service type from Table 21.1 (Service Management chapter un.docx
DinahShipman862
 
Choose a scene from a movie.Watch the scene with the sound on, the.docx
Choose a scene from a movie.Watch the scene with the sound on, the.docxChoose a scene from a movie.Watch the scene with the sound on, the.docx
Choose a scene from a movie.Watch the scene with the sound on, the.docx
DinahShipman862
 
Choose a resident microbe from the FAQ Human Microbiome document th.docx
Choose a resident microbe from the FAQ Human Microbiome document th.docxChoose a resident microbe from the FAQ Human Microbiome document th.docx
Choose a resident microbe from the FAQ Human Microbiome document th.docx
DinahShipman862
 
Choose a personality theory that justifiably aligns with your perspe.docx
Choose a personality theory that justifiably aligns with your perspe.docxChoose a personality theory that justifiably aligns with your perspe.docx
Choose a personality theory that justifiably aligns with your perspe.docx
DinahShipman862
 
choose a role researcher, consultant, or organizational leader. In .docx
choose a role researcher, consultant, or organizational leader. In .docxchoose a role researcher, consultant, or organizational leader. In .docx
choose a role researcher, consultant, or organizational leader. In .docx
DinahShipman862
 
Choose a personality disorder (e.g., borderline, antisocial, narciss.docx
Choose a personality disorder (e.g., borderline, antisocial, narciss.docxChoose a personality disorder (e.g., borderline, antisocial, narciss.docx
Choose a personality disorder (e.g., borderline, antisocial, narciss.docx
DinahShipman862
 
Choose a single toxicant, and explain how it can impact the immune s.docx
Choose a single toxicant, and explain how it can impact the immune s.docxChoose a single toxicant, and explain how it can impact the immune s.docx
Choose a single toxicant, and explain how it can impact the immune s.docx
DinahShipman862
 
Choose a non-communicable disease such as cancer, diabetes, cardiova.docx
Choose a non-communicable disease such as cancer, diabetes, cardiova.docxChoose a non-communicable disease such as cancer, diabetes, cardiova.docx
Choose a non-communicable disease such as cancer, diabetes, cardiova.docx
DinahShipman862
 
Choose a musical artist (from any music era) and provide a 1-2 page .docx
Choose a musical artist (from any music era) and provide a 1-2 page .docxChoose a musical artist (from any music era) and provide a 1-2 page .docx
Choose a musical artist (from any music era) and provide a 1-2 page .docx
DinahShipman862
 
Choose a news article from either a physical newspaper or online new.docx
Choose a news article from either a physical newspaper or online new.docxChoose a news article from either a physical newspaper or online new.docx
Choose a news article from either a physical newspaper or online new.docx
DinahShipman862
 
Choose a president from this unit (George Washington to John Quincy .docx
Choose a president from this unit (George Washington to John Quincy .docxChoose a president from this unit (George Washington to John Quincy .docx
Choose a president from this unit (George Washington to John Quincy .docx
DinahShipman862
 
Choose a control system that has direct impact on your daily life. E.docx
Choose a control system that has direct impact on your daily life. E.docxChoose a control system that has direct impact on your daily life. E.docx
Choose a control system that has direct impact on your daily life. E.docx
DinahShipman862
 
Choose a culture that interests you or one that you want to learn mo.docx
Choose a culture that interests you or one that you want to learn mo.docxChoose a culture that interests you or one that you want to learn mo.docx
Choose a culture that interests you or one that you want to learn mo.docx
DinahShipman862
 

More from DinahShipman862 (20)

Choose one ethical dilemma from each groupGroup A A newspaper c.docx
Choose one ethical dilemma from each groupGroup A A newspaper c.docxChoose one ethical dilemma from each groupGroup A A newspaper c.docx
Choose one ethical dilemma from each groupGroup A A newspaper c.docx
 
Choose one of the following artworks or artists for your Final Rep.docx
Choose one of the following artworks or artists for your Final Rep.docxChoose one of the following artworks or artists for your Final Rep.docx
Choose one of the following artworks or artists for your Final Rep.docx
 
Choose between1. Your company wants to export cultural artifacts .docx
Choose between1. Your company wants to export cultural artifacts .docxChoose between1. Your company wants to export cultural artifacts .docx
Choose between1. Your company wants to export cultural artifacts .docx
 
Choose at least two (2) items or events that you would consider to b.docx
Choose at least two (2) items or events that you would consider to b.docxChoose at least two (2) items or events that you would consider to b.docx
Choose at least two (2) items or events that you would consider to b.docx
 
Choose any song you wish (contemporary is fine). Look up the lyrics .docx
Choose any song you wish (contemporary is fine). Look up the lyrics .docxChoose any song you wish (contemporary is fine). Look up the lyrics .docx
Choose any song you wish (contemporary is fine). Look up the lyrics .docx
 
Choose any medicalhealthcare research institute and describe the or.docx
Choose any medicalhealthcare research institute and describe the or.docxChoose any medicalhealthcare research institute and describe the or.docx
Choose any medicalhealthcare research institute and describe the or.docx
 
Choose any aspect of the population geographydemographic landscape .docx
Choose any aspect of the population geographydemographic landscape .docxChoose any aspect of the population geographydemographic landscape .docx
Choose any aspect of the population geographydemographic landscape .docx
 
Choose a service type from Table 21.1 (Service Management chapter un.docx
Choose a service type from Table 21.1 (Service Management chapter un.docxChoose a service type from Table 21.1 (Service Management chapter un.docx
Choose a service type from Table 21.1 (Service Management chapter un.docx
 
Choose a scene from a movie.Watch the scene with the sound on, the.docx
Choose a scene from a movie.Watch the scene with the sound on, the.docxChoose a scene from a movie.Watch the scene with the sound on, the.docx
Choose a scene from a movie.Watch the scene with the sound on, the.docx
 
Choose a resident microbe from the FAQ Human Microbiome document th.docx
Choose a resident microbe from the FAQ Human Microbiome document th.docxChoose a resident microbe from the FAQ Human Microbiome document th.docx
Choose a resident microbe from the FAQ Human Microbiome document th.docx
 
Choose a personality theory that justifiably aligns with your perspe.docx
Choose a personality theory that justifiably aligns with your perspe.docxChoose a personality theory that justifiably aligns with your perspe.docx
Choose a personality theory that justifiably aligns with your perspe.docx
 
choose a role researcher, consultant, or organizational leader. In .docx
choose a role researcher, consultant, or organizational leader. In .docxchoose a role researcher, consultant, or organizational leader. In .docx
choose a role researcher, consultant, or organizational leader. In .docx
 
Choose a personality disorder (e.g., borderline, antisocial, narciss.docx
Choose a personality disorder (e.g., borderline, antisocial, narciss.docxChoose a personality disorder (e.g., borderline, antisocial, narciss.docx
Choose a personality disorder (e.g., borderline, antisocial, narciss.docx
 
Choose a single toxicant, and explain how it can impact the immune s.docx
Choose a single toxicant, and explain how it can impact the immune s.docxChoose a single toxicant, and explain how it can impact the immune s.docx
Choose a single toxicant, and explain how it can impact the immune s.docx
 
Choose a non-communicable disease such as cancer, diabetes, cardiova.docx
Choose a non-communicable disease such as cancer, diabetes, cardiova.docxChoose a non-communicable disease such as cancer, diabetes, cardiova.docx
Choose a non-communicable disease such as cancer, diabetes, cardiova.docx
 
Choose a musical artist (from any music era) and provide a 1-2 page .docx
Choose a musical artist (from any music era) and provide a 1-2 page .docxChoose a musical artist (from any music era) and provide a 1-2 page .docx
Choose a musical artist (from any music era) and provide a 1-2 page .docx
 
Choose a news article from either a physical newspaper or online new.docx
Choose a news article from either a physical newspaper or online new.docxChoose a news article from either a physical newspaper or online new.docx
Choose a news article from either a physical newspaper or online new.docx
 
Choose a president from this unit (George Washington to John Quincy .docx
Choose a president from this unit (George Washington to John Quincy .docxChoose a president from this unit (George Washington to John Quincy .docx
Choose a president from this unit (George Washington to John Quincy .docx
 
Choose a control system that has direct impact on your daily life. E.docx
Choose a control system that has direct impact on your daily life. E.docxChoose a control system that has direct impact on your daily life. E.docx
Choose a control system that has direct impact on your daily life. E.docx
 
Choose a culture that interests you or one that you want to learn mo.docx
Choose a culture that interests you or one that you want to learn mo.docxChoose a culture that interests you or one that you want to learn mo.docx
Choose a culture that interests you or one that you want to learn mo.docx
 

Recently uploaded

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 

Recently uploaded (20)

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 

Chapter 55.1 Describe the circumstances in which you would c.docx

  • 1. Chapter 5 5.1 Describe the circumstances in which you would choose to use embedded SQL rather than SQL alone or only a general-purpose programming language. Answer: 5.2 Write a Java function using JDBC metadata features that takes a ResultSet as an input parameter, and prints out the result in tabular form, with appropriate names as column headings. Answer: 5.3 Write a Java function using JDBC metadata features that prints a list of all relations in the database, displaying for each relation the names and types of its attributes. Answer: 5.4 Show how to enforce the constraint “ an instructor cannot teach in two different classrooms in a semester in the same time slot. ” using a trigger (remember that the constraint can be violated by changes to the teaches
  • 2. relation as well as to the section relation). Answer: 5.5 Write triggers to enforce the referential integrity constraint from section to time slot , on updates to section , and time in Figure 5.8 do not cover the update operation. slot . Note that the ones we wrote 5.6 To maintain the tot cred attribute of the student relation, carry out the fol- lowing: a. Modify the trigger on updates of takes , to handle all updates that can affect the value of tot b. Write a trigger to handle inserts to the
  • 3. takes relation. cred . c. Under what assumptions is it reasonable not to create triggers on the course relation? Answer: 5.7 Consider the bank database of Figure 5.25. Let us define a view branch cust as follows: create view branch cust as select branch name, customer name from depositor, account where depositor.account number = account.account number Answer: 5.8 Consider the bank database of Figure 5.25. Write an SQL trigger to carry out the following action: On delete of an account, for each owner of the account, check if the owner has any remaining accounts, and if she does not, delete her from the
  • 4. depositor relation. Answer: 5.9 Show how to express group by cube ( a , b , c , d ) using rollup ; your answer should have only one group by clause. Answer: 5.10 Given a relation S ( student , subject , marks ), write a query to find the top n students by total marks, by using ranking. Answer:
  • 5. 5.11 Consider the sales relation from Section 5.6.Write an SQL query to compute the cube operation on the relation, giving the relation in Figure 5.21. Do not use the cube construct. Answer: 5.12 Consider the following relations for a company database: • emp ( ename , dname , salary ) • mgr ( ename , mname ) and the Java code in Figure 5.26, which uses the JDBC API. Assume that the userid, password, machine name, etc. are all okay. Describe in concise English what the Java program does. (That is, produce an English sentence like “It finds the manager of the toy department,” not a line-by-line description of what each Java statement does.) Answer:
  • 6. 5.13 Suppose you were asked to define a class MetaDisplay in Java, containing a method static void printTable(String r) ; the method takes a relation name r as input, executes the query “ select * from r ” , and prints the result out in nice tabular format, with the attribute names displayed in the header of the table. import java.sql.*; public class Mystery { public static void main(String[] args) { try { Connection con=null; Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection( "jdbc:oracle:thin:star/ [email protected] //edgar.cse.lehigh.edu:1521/XE"); Statement s=con.createStatement(); String q; String empName = "dog"; boolean more; ResultSet result;
  • 7. do { q = "select mname from mgr where ename = ’" + empName + "’"; result = s.executeQuery(q); more = result.next(); if (more) { empName = result.getString("mname"); System.out.println (empName); } } while (more); s.close(); con.close(); } catch(Exception e) { e.printStackTrace(); } }} a. What do you need to know about relation r to be able to print the result in the specified tabular format. b. What JDBC methods(s) can get you the required information? c. Write the method printTable(String r) using the JDBC API. Answer: 5.14 Repeat Exercise 5.13 using ODBC , defining void printTable(char *r)
  • 8. as a function instead of a method. Answer: 5.15 Consider an employee database with two relations employee ( employee name , street , city ) works ( employee name , company name , salary ) where the primary keys are underlined. Write a query to find companies whose employees earn a higher salary, on average, than the average salary at “ First Bank Corporation ” . a. Using SQL functions as appropriate. b. Without using SQL functions. Answer: 5.16 Rewrite the query in Section 5.2.1 that returns the name and budget of all
  • 9. departments with more than 12 instructors, using the with clause instead of using a function call. Answer: 5.17 Compare the use of embedded SQL with the use in SQL of functions defined in a general-purpose programming language. Under what circumstances would you use each of these features? Answer: 5.18 Modify the recursive query in Figure 5.15 to define a relation prereq depth ( course id , prereq id , depth ) where the attribute depth indicates how many levels of intermediate prerequisites are there between the course and the prerequisite. Direct prerequisites have a depth of 0. Answer: 5.19 Consider the relational schema part (
  • 10. part id , name , cost ) subpart ( part id , subpart id , count ) A tuple ( p 1 , p 2 , 3) in the subpart relation denotes that the part with part-id p 2 is a direct subpart of the part with part-id p 1, and p 1 has 3 copies of p 2. Note that p 2 may itself have further subparts. Write a recursive SQL query that outputs the names of all subparts of the part with part-id
  • 11. “ P-100 ” . Answer: 5.20 Consider again the relational schema from Exercise 5.19. Write a JDBC function using non-recursive SQL to find the total cost of part “ P-100 ” ,including the costs of all its subparts. Be sure to take into account the fact that a part may have multiple occurrences of a subpart. You may use recursion in Java if you wish. Answer: 5.21 Suppose there are two relations r and s , such that the foreign key B of r references the primary key A of s
  • 12. . Describe how the trigger mechanism can be used to implement the on delete cascade option,when a tuple is deleted from s . Answer: 5.22 The execution of a trigger can cause another action to be triggered. Most database systems place a limit on how deep the nesting can be. Explain why they might place such a limit. Answer: 5.23 Consider the relation, r , shown in Figure 5.27. Give the result of the following query: uilding room number time slot id course id sec id Garfield Garfield Saucon Saucon Painter Painter 359 359 651 550 705 403
  • 13. A B A C D D BIO-101 BIO-101 CS-101 CS-319 MU-199 FIN-201 1 2 2 1 1 1 select building , room number , time slot id , count (*) from r group by rollup ( building , room number , time slot id ) Answer: 5.24 For each of the SQL aggregate functions sum, count, min , and max , show how to compute the aggregate value on a multiset S 1 ∪
  • 14. S 2 , given the aggregate values on multisets S 1 and S 2 . On the basis of the above, give expressions to compute aggregate values with grouping on a subset S of the attributes of a relation r ( A , B , C , D , E ), given aggregate values for grouping on attributes T ⊇ S , for the following aggregate functions: a. sum, count, min, and max b. avg c. Standard deviation
  • 15. Answer: 5.25 In Section 5.5.1, we used the student grades view of Exercise 4.5 to write a query to find the rank of each student based on grade-point average. Modify that query to show only the top 10 students (that is, those students whose rank is 1 through 10). Answer: 5.26 Give an example of a pair of groupings that cannot be expressed by using a single group by clause with cube and rollup . 5.27 Given relation s ( a , b , c ), show how to use the extended SQL features to generate a histogram of c versus a , dividing
  • 16. a into 20 equal-sized partitions (that is, where each partition contains 5 percent of the tuples in s , sorted by a ). Answer: 5.28 Consider the bank database of Figure 5.25 and the balance attribute of the account relation. Write an SQL query to compute a histogram of balance values, dividing the range 0 to the maximum account balance present, into three equal ranges. Answer: