0 évaluation0% ont trouvé ce document utile (0 vote)
29 vues11 pages
Database Project II – Oracle (Investment Database)
Description of Project: In this project you are to create the STOCK, MANAGER, PORTFOLIO and HOLDING tables as follows:
INVESTMENTS DATABASE
MANAGER
Manager Manager
Number Name Salary
M1 Smith 45000.00
M2 Brown 62500.00
M3 Jones 43900.00
STOCK
Stock Stock Current
Symbol Name Price
JFM Jetform 21.75
JDS JDS Fitel 20.55
NTL NorTel 54.10
COS Corel 3.16
MLT Mitel Corp. 14.30
CSN Cognos 27.50
RIM Research In Motion 90.95
PORTFOLIO
Portfolio Manager
Number Number Cash
P001 M2 25000
P004 M3 10000
P005 M2 50000
P008 M3 37500
P011 M3 8000
HOLDING
Portfolio Stock Purchase Number Purchase
Number Symbol Date Shares Price
P001 JFM 10-1-1998 300 19.55
P004 NTL 10-2-1998 200 52.90
P001 CSN 10-5-1998 150 29.90
P005 MLT 10-6-1998 500 12.00
P001 JFM 9-30-1998 300 19.30
P008 COS 9-29-1998 800 4.50
P008 CSN 9-29-1998 500 25.00
P001 NTL 9-30-1998 250 56.40
P005 COS 9-30-1998 1200 3.60
P001 CSN 10-6-1998 250 29.75
P001 COS 10-7-1998 200 3.50
P001 JFM 10-2-1998 300 19.55
P004 MLT 10-13-1998 200 12.20
P005 MLT 10-13-1998 600 12.25
P008 JDS 10-28-1998 610 21.50
P008 JFM 10-14-1998 500 20.50
1. Create the Stock, Manager, Portfolio and Holding tables as shown above. Choose the name of fields carefully. Include a primary key clause for each table.
2. Run the attached script file, stock.sql after making appropriate changes to your stock table name.
3. Insert the data shown for the Manager table.
4. Run the attached script file, portfolio.sql to load the data into the Portfolio table.
5. Run the attached script file: holding.sql to load the data into the Holding table.
6. Use the ALTER TABLE command to:
• make manager number a foreign key in the Portfolio table.
• make portfolio number and stock symbol foreign keys in the Holding table.
7. Use the ALTER TABLE command to add a check clause on the SALARY column in the Manager table to ensure the salary value is at least $40,000.
8. Write select statements for the following queries:
• display the entries in the stock table in descending order of price
• display all entries in the stock table where the stock name starts with a C
• display the portfolio number and stock symbol of all entries in the holding table that have more than 600 shares
• display the average price of stock in the stock table
• using a join, display the portfolio number, cash, stock symbol and number of shares from the portfolio and holding tables
• using a subquery, display the stock name of all stock held in portfolio P008
9. Create the following views:
• create a view called share_price that contains the portfolio number, stock symbol and current price of the stock.
• create a view called manager_cash that contains the manager number and the total cash in portfolios managed by the manager.
10. Display the stock name of all stock in portfolios managed by manager M2
a) using a join
b) using a subquery
11. Display the stock name of all stock purchased during September of 1998
a) using a join
b) using a subquery
12. Display the portfolio number of the portfolio that has the holding with the largest number of shares in it
13. Display the portfolio number of the portfolio that has the holding with the largest current value (number shares x current price)
14. Display the stock name of all stock that is in portfolio P001 but not in portfolio P005. Hint: use IN/NOT IN
15. List all stock (stock symbol, name and current price) of all st
Titre original
Database Project II – Oracle (Investment Database)
Database Project II – Oracle (Investment Database)
Description of Project: In this project you are to create the STOCK, MANAGER, PORTFOLIO and HOLDING tables as follows:
INVESTMENTS DATABASE
MANAGER
Manager Manager
Number Name Salary
M1 Smith 45000.00
M2 Brown 62500.00
M3 Jones 43900.00
STOCK
Stock Stock Current
Symbol Name Price
JFM Jetform 21.75
JDS JDS Fitel 20.55
NTL NorTel 54.10
COS Corel 3.16
MLT Mitel Corp. 14.30
CSN Cognos 27.50
RIM Research In Motion 90.95
PORTFOLIO
Portfolio Manager
Number Number Cash
P001 M2 25000
P004 M3 10000
P005 M2 50000
P008 M3 37500
P011 M3 8000
HOLDING
Portfolio Stock Purchase Number Purchase
Number Symbol Date Shares Price
P001 JFM 10-1-1998 300 19.55
P004 NTL 10-2-1998 200 52.90
P001 CSN 10-5-1998 150 29.90
P005 MLT 10-6-1998 500 12.00
P001 JFM 9-30-1998 300 19.30
P008 COS 9-29-1998 800 4.50
P008 CSN 9-29-1998 500 25.00
P001 NTL 9-30-1998 250 56.40
P005 COS 9-30-1998 1200 3.60
P001 CSN 10-6-1998 250 29.75
P001 COS 10-7-1998 200 3.50
P001 JFM 10-2-1998 300 19.55
P004 MLT 10-13-1998 200 12.20
P005 MLT 10-13-1998 600 12.25
P008 JDS 10-28-1998 610 21.50
P008 JFM 10-14-1998 500 20.50
1. Create the Stock, Manager, Portfolio and Holding tables as shown above. Choose the name of fields carefully. Include a primary key clause for each table.
2. Run the attached script file, stock.sql after making appropriate changes to your stock table name.
3. Insert the data shown for the Manager table.
4. Run the attached script file, portfolio.sql to load the data into the Portfolio table.
5. Run the attached script file: holding.sql to load the data into the Holding table.
6. Use the ALTER TABLE command to:
• make manager number a foreign key in the Portfolio table.
• make portfolio number and stock symbol foreign keys in the Holding table.
7. Use the ALTER TABLE command to add a check clause on the SALARY column in the Manager table to ensure the salary value is at least $40,000.
8. Write select statements for the following queries:
• display the entries in the stock table in descending order of price
• display all entries in the stock table where the stock name starts with a C
• display the portfolio number and stock symbol of all entries in the holding table that have more than 600 shares
• display the average price of stock in the stock table
• using a join, display the portfolio number, cash, stock symbol and number of shares from the portfolio and holding tables
• using a subquery, display the stock name of all stock held in portfolio P008
9. Create the following views:
• create a view called share_price that contains the portfolio number, stock symbol and current price of the stock.
• create a view called manager_cash that contains the manager number and the total cash in portfolios managed by the manager.
10. Display the stock name of all stock in portfolios managed by manager M2
a) using a join
b) using a subquery
11. Display the stock name of all stock purchased during September of 1998
a) using a join
b) using a subquery
12. Display the portfolio number of the portfolio that has the holding with the largest number of shares in it
13. Display the portfolio number of the portfolio that has the holding with the largest current value (number shares x current price)
14. Display the stock name of all stock that is in portfolio P001 but not in portfolio P005. Hint: use IN/NOT IN
15. List all stock (stock symbol, name and current price) of all st
Database Project II – Oracle (Investment Database)
Description of Project: In this project you are to create the STOCK, MANAGER, PORTFOLIO and HOLDING tables as follows:
INVESTMENTS DATABASE
MANAGER
Manager Manager
Number Name Salary
M1 Smith 45000.00
M2 Brown 62500.00
M3 Jones 43900.00
STOCK
Stock Stock Current
Symbol Name Price
JFM Jetform 21.75
JDS JDS Fitel 20.55
NTL NorTel 54.10
COS Corel 3.16
MLT Mitel Corp. 14.30
CSN Cognos 27.50
RIM Research In Motion 90.95
PORTFOLIO
Portfolio Manager
Number Number Cash
P001 M2 25000
P004 M3 10000
P005 M2 50000
P008 M3 37500
P011 M3 8000
HOLDING
Portfolio Stock Purchase Number Purchase
Number Symbol Date Shares Price
P001 JFM 10-1-1998 300 19.55
P004 NTL 10-2-1998 200 52.90
P001 CSN 10-5-1998 150 29.90
P005 MLT 10-6-1998 500 12.00
P001 JFM 9-30-1998 300 19.30
P008 COS 9-29-1998 800 4.50
P008 CSN 9-29-1998 500 25.00
P001 NTL 9-30-1998 250 56.40
P005 COS 9-30-1998 1200 3.60
P001 CSN 10-6-1998 250 29.75
P001 COS 10-7-1998 200 3.50
P001 JFM 10-2-1998 300 19.55
P004 MLT 10-13-1998 200 12.20
P005 MLT 10-13-1998 600 12.25
P008 JDS 10-28-1998 610 21.50
P008 JFM 10-14-1998 500 20.50
1. Create the Stock, Manager, Portfolio and Holding tables as shown above. Choose the name of fields carefully. Include a primary key clause for each table.
2. Run the attached script file, stock.sql after making appropriate changes to your stock table name.
3. Insert the data shown for the Manager table.
4. Run the attached script file, portfolio.sql to load the data into the Portfolio table.
5. Run the attached script file: holding.sql to load the data into the Holding table.
6. Use the ALTER TABLE command to:
• make manager number a foreign key in the Portfolio table.
• make portfolio number and stock symbol foreign keys in the Holding table.
7. Use the ALTER TABLE command to add a check clause on the SALARY column in the Manager table to ensure the salary value is at least $40,000.
8. Write select statements for the following queries:
• display the entries in the stock table in descending order of price
• display all entries in the stock table where the stock name starts with a C
• display the portfolio number and stock symbol of all entries in the holding table that have more than 600 shares
• display the average price of stock in the stock table
• using a join, display the portfolio number, cash, stock symbol and number of shares from the portfolio and holding tables
• using a subquery, display the stock name of all stock held in portfolio P008
9. Create the following views:
• create a view called share_price that contains the portfolio number, stock symbol and current price of the stock.
• create a view called manager_cash that contains the manager number and the total cash in portfolios managed by the manager.
10. Display the stock name of all stock in portfolios managed by manager M2
a) using a join
b) using a subquery
11. Display the stock name of all stock purchased during September of 1998
a) using a join
b) using a subquery
12. Display the portfolio number of the portfolio that has the holding with the largest number of shares in it
13. Display the portfolio number of the portfolio that has the holding with the largest current value (number shares x current price)
14. Display the stock name of all stock that is in portfolio P001 but not in portfolio P005. Hint: use IN/NOT IN
15. List all stock (stock symbol, name and current price) of all st
Investment: Manager, Stock, Portfolio, and Holding
Oracle Database 1) Create the Stock, Manager, Portfolio and Holding tables as shown above. Choose the name of fields carefully. nclude a !rimary key clause for each table. ") #un the attached scri!t file, stock.s$l after making a!!ro!riate changes to your stock table name. %) nsert the data shown for the Manager table. &) #un the attached scri!t file, !ortfolio.s$l to load the data into the Portfolio table. ') #un the attached scri!t file( holding.s$l to load the data into the Holding table. Output result for stock: Output result for portfolio: Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database Output result for holdin!: Output result for mana!er: Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database )) *se the +,-.# -+/,. command to( a. make manager number a foreign key in the Portfolio table. b. make !ortfolio number and stock symbol foreign keys in the Holding table. 0) *se the +,-.# -+/,. command to add a check clause on the S+,+#1 column in the Manager table to ensure the salary value is at least 2&3,333. Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database 4) 5rite select statements for the following $ueries( a" displa# the entries in the stock table in descendin! order of price b" displa# all entries in the stock table $here the stock name starts $ith a % c" displa# the portfolio number and stock s#mbol of all entries in the holdin! table that ha&e more than '00 shares Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database
d" displa# the a&era!e price of stock in the stock table e" usin! a (oin, displa# the portfolio number, cash, stock s#mbol and number of shares from the portfolio and holdin! tables Output One: Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database Output Two: f" usin! a sub)uer#, displa# the stock name of all stock held in portfolio *008 6) Create the following views( a. create a view called share7!rice that contains the !ortfolio number, stock symbol and current !rice of the stock. Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database b. create a view called manager7cash that contains the manager number and the total cash in !ortfolios managed by the manager. Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database 13)8is!lay the stock name of all stock in !ortfolios managed by manager M" a. using a 9oin
Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database b. using a sub$uery 11)8is!lay the stock name of all stock !urchased during Se!tember of 1664. a. using a 9oin b. using a sub$uery Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database 1")8is!lay the !ortfolio number of the !ortfolio that has the holding with the largest number of shares in it 1%)8is!lay the !ortfolio number of the !ortfolio that has the holding with the largest current value :number shares ; current !rice) 1&)8is!lay the stock name of all stock that is in !ortfolio P331 but not in !ortfolio P33'. Hint( use <=<>- < 1'),ist all stock :stock symbol, name and current !rice) of all stock not included in any !ortfolio( using <>- < using an outer 9oin Zubaidah Abdul Rehman, 20042080, BI Database Management System Investment: Manager, Stock, Portfolio, and Holding Oracle Database
1))?or all stock in the Stock table, list the stock symbol, stock name and the total value :current !rice ; number shares) of the stock in all holdings. 10)?or each !ortfolio in the Portfolio table, list the !ortfolio number and total shares held in that !ortfolio@ only include !ortfolios with more than two holdings. References <otes( SA, -utorial +dditional SA, Slides Zubaidah Abdul Rehman, 20042080, BI