Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1.
Create above relations using your own data types and print the structure of the each
relation.
Insert at least 10 records in the relation EMPLOYEE and 5 records in the relation
COMPANY. Insert appropriate records in the relations WORKS and MANAGES.
Print the contents of the each relation.
Give an expression in SQL with output for each of the following queries:
Find the names of all employees who work for First Bank Corporation.
Find the names and cities of residence of all employees who work for the First Bank
Corporation.
Find the names, street, and cities of residence of all employees who work for First Bank
Corporation and earn more than Rs. 10,000/-.
Find the employees who live in the same cities as the companies for which they work.
Find all employees who live in the same cities and on the same streets as do their
managers.
Find all employees who do not work for First Bank Corporation.
Find all employees who earn more than every employee of Small Bank Corporation.
Find all companies located in every city in which Small Bank Corporation is located.
Find all employees who earn more than the average salary of all employees of their
company.
Find the company that has the most employees.
Find the company that has the smallest payroll.
Find those companies whose employees earn a higher salary, on average, than the
average salary at First Bank Corporation.
Set 3: Constraints, Views, etc.
Create the tables based on the following table instance charts. Choose the appropriate
datatypes and be sure to add integrity constraints.
MEMBER_ID
LAST_NAME
FIRST_NAME
ADDRESS
CITY
PHONE
JOIN_
DATE
PK
NN, U
Number
NN
NN
VARCHAR2
System
Date
Date
VARCHAR2
VARCHAR2 VARCHAR2
VARCHAR2
10
Length
25
25
100
30
15
TITLE_ID
TITLE
DESCRIPTION
NN
NN
RATING
CATEGORY
RELEASE_ DATE
PK
NN, U
DRAMA, COMEDY,
ACTION, CHILD, SCIFI,
DOCUMENTARY
VARCHAR2
VARCHAR2
4
20
G, PG, R,
NC17, NR
Check
Datatype
Length
Number
10
VARCHAR2
60
VARCHAR2
400
Date
COPY _ID
TITLE_ID
PK
NN, U
PK, FK
NN, U
Number
10
TITLE
TITLE_ID
Number
10
Key Type
NullI/ Unique
Check
FK Ref Table
FK Ref Col
Datatype
Length
STATUS
NN
AVAILABLE, DESTROYED, RENTED, RESERVED
VARCHAR2
15
BOOK_DATE MEMBER_ID
PK
2.
(a)
TITLE_ID
PK, FK2
PK, FK2
ACT_RET_DATE
MEMBER
Date
EXP_RET_DATE
System Date + 2
Days
System Date
FK Ref Table
FK Ref Col
Datatype
Length
PK, FK1
COPY_ID
MEMBER_ID
Number
10
TITLE_
COPY
COPY_ID
Number
10
TITLE_
COPY
TITLE_ID
Number
10
Date
Date
Add data to the TITLE table. Be sure to use sequence to add the TITLE ID. The
sequence must start with 92.
Title
Willie and
Christmas Too
Description
All of Willies friends make a Christmas list
for Santa, but Willie has yet to add his own
Rating
Category
Release_Date
CHILD
05-OCT-1995
wish list.
Yet another installation of science fiction
Alien Again
history. Can the heroine save the planet from
the alien life form?
A meteor crashes near a small American
The Glob
town and unleashes carnivorous goo in this
classic.
With a little luck and a lot of ingenuity, a
My Day Off
teenager skips school for a day in New York.
A six-year-old has doubts about Santa Claus,
Miracles on Ice
but she discovers that miracles really do exist.
After discovering a cache of drugs, a young
Soda Gang
couple find themselves pitted against a
vicious gang.
(b)
SCIFI
19-MAY-1995
NR
SCIFI
12-AUG-1995
PG
COMEDY
12-JUL-1995
PG
DRAMA
12-SEP-1995
NR
ACTION
01-JUN-1995
Add data to the MEMBER table. Write a script named S3Q2B.SQL to prompt
users for the information. Execute the script. Be sure to use sequence to add the
member number. The sequence must start with 101.
(c)
Address
City
283 King Street Seattle
5 Modrany
Bratislava
Phone
206-899-6666
586-355-8882
Join_Date
08-MAR-1990
08-MAR-1990
Midori
Mark
Audry
Nagayama
68 Via Centrale Sao Paolo
Quick-to-See 6921 King Way Lagos
Ropeburn
86 Chu Street
Hong Kong
254-852-5764
63-559-7777
41-559-87
17-JUN-1991
07-APR-1990
18-JAN-1991
Molly
Urguhart
418-542-9988
18-JAN-1991
3035 Laurier
Quebec
Miracles on Ice
Soda Gang
(d)
COPY_ID
1
Status
AVAILABLE
1
2
1
1
2
3
1
1
AVAILABLE
RENTED
AVAILABLE
AVAILABLE
AVAILABLE
RENTED
AVAILABLE
AVAILABLE
Title_Id
Copy_Id
Member_Id
Book_Date
Exp_Ret_Date Act_Ret_Date
92
101
3 days ago.
1 day ago
93
95
97
2
3
I
101
102
106
1 day ago
2 days ago
4 days ago
2 days ago
3.
Create a view named TITLE_AVAIL to show the movie titles and the availability of each
copy and its expected return date if rented (TITLE, COPY_ID, STATUS, and
EXP_RET_DATE). Query all rows from the view. Order the results by title.
4.
5.
(a)
Add a new title. The movie is Interstellar Wars, which is rated PG and
classified as a SCIFI movie. The release date is 07-JUL-77. The description is
Futuristic interstellar action movie. Can the rebels save the humans from the evil
empire? Be sure to add a title copy record for two copies.
(b)
Enter two reservations. One reservation is for Carmen Velasquez, who wants to
rent Interstellar Wars. The other is for Mark Quick-to-See, who wants to rent
Soda Gang.
(c)
Customer Carmen Velasquez rents the movie Interstellar Wars, copy 1. Remove
her reservation for the movie. Record the information about the rental. Allow the
default value for the expected return date to be used. Verify that the rental was
recorded by using the view you created.
Create a report titled Customer History Report. This report will contain each customers
history of renting videos. Be sure to include the customer name, movie rented, dates of
the rental, and duration of rentals. Total the number of rentals for all customers for the
reporting period. Save the script in a file named S3Q5.SQL.
Set 4: PL/SQL
Consider the tables of Set 3 and perform the following:
1.
2.
3.
4.
5.
Write a procedure to display member id, name and address of all members using cursors.
Write a function to return the availability of given title.
Write a trigger to check whether required title is available before issuing for rent. If the
required copy is not available then raise the appropriate exception and show the message.
Write a trigger to update the status of given copy of a title after returned by the member.
Write a trigger to restrict issue and return on Sundays.